Window
HTML window event attributes manage user interactions and changes in the browser window, such as resizing, scrolling, and focus events.
Window event
HTML window
event attributes are used to handle events related to the window object, such as resizing, scrolling, or focusing. These events help developers respond to user actions and changes in the browser window.
Common window event
onresize
: Triggered when the window is resized.
index.html
<body onresize="alert('Window resized!')">
onscroll
: Fired when the user scrolls within the window or a scrollable element.
index.html
<body onscroll="console.log('Scrolled!')">
onfocus
: Activated when the window gains focus.
index.html
<body onfocus="console.log('Window focused!')">
onblur
: Fired when the window loses focus.
index.html
<body onblur="console.log('Window blurred!')">
onload
: Occurs when the window has finished loading.
index.html
<body onload="console.log('Window loaded!')">
onunload
: Triggered when the window is about to be unloaded (e.g., user leaves the page).
index.html
<body onunload="console.log('Window unloaded!')">
These attributes allow developers to create dynamic, responsive behaviors based on user interactions and changes in the browser window.
Conclusion
HTML window
event attributes manage interactions and changes within the browser window, such as resizing, scrolling, and focus changes. Common events include onresize
, onscroll
, and onload
, which allow developers to create dynamic behaviors based on user actions. These events enhance user experience by responding to actions like window resizing or gaining/losing focus.