HTML onpagehide Event Attributes

The onpagehideHTML event attribute is an advanced feature in web development that allows developers to detect when a webpage is about to be hidden from the user's view. This event is triggered when the user navigates away from the page, closes the tab, or switches to another tab, providing an opportunity to save data, clean up resources, or handle session management.

Defining HTML onpagehide Event Attributes

The onpagehideevent is fired on the windowobject when a page is about to be hidden, either due to navigation to a new page or the browser minimizing the tab. Unlike the onunloadevent, which is triggered only during a full unload of the page, onpagehideis triggered even if the page remains in the browser’s session history (e.g., during page caching).
This event is part of the Page Lifecycle API, which provides finer control over page visibility and state management.

Window Event Attributes

AttributesDescription
onafterprintFires after the document has started printing or the print dialog box has been closed.
onbeforeprintFires before the document is about to be printed.
onbeforeunloadFires when the document is about to be unloaded.
onerrorFires when an error occurs during loading of an external file (e.g., images or scripts).
onhashchangeFires when the anchor part of the URL has changed.
onloadFires when the page has finished loading.
onmessageFires when a message is received through an event source (e.g., WebSocket or iframe).
onofflineFires when the browser starts working offline.
ononlineFires when the browser starts working online.
onpagehideFires when the user navigates away from a webpage.
onpageshowFires when the user navigates to a webpage.
onpopstateFires when the active history entry changes (e.g., when the user clicks the back or forward button).
onresizeFires when the browser window is resized.
onstorageFires when a Web Storage area is updated (e.g., localStorage or sessionStorage).
onunloadFires once a page is unloaded (or the browser window is closed).

Important Notes:

We are currently focusing on showcasing window events, providing valuable insights into their functionality and use cases. In the near future, we plan to expand our resources by introducing a comprehensive guide covering A-to-Z HTML event attributes. This addition will serve as a complete reference for developers at all levels, empowering you to effectively utilize event attributes in your projects. Stay connected for these upcoming enhancements.

HTML AttributesGlobal AttributesEvent Attributes
To view the full list
To view the full list
To view the full list
elements Chrome BrowsersMicrosoft Edge BrowserFirefox BrowsersSafari BrowserOpera Browser
onpagehideYes11.0Yes5.0Yes