The pagehide
event is sent to a Window
when the browser hides the current page in the process of presenting a different page from the session's history. For example, when the user clicks the browser's Back button, the current page receives a pagehide
event before the previous page is shown.
Bubbles | No |
---|---|
Cancelable | No |
Interface | PageTransitionEvent |
Event handler property | onpagehide |
Example
In this example, an event handler is established to watch for pagehide
events and to perform special handling if the page is being persisted for possible reuse.
window.addEventListener("pagehide", event => { if (event.persisted) { /* the page isn't being discarded, so it can be reused later */ } }, false);
This can also be written using the onpagehide
event handler property on the Window
:
window.onpagehide = event => { if (event.persisted) { /* the page isn't being discarded, so it can be reused later */ } }
Specifications
Specification | Status | Comment |
---|---|---|
HTML Living Standard The definition of 'pagehide' in that specification. |
Living Standard | Initial specification. |
HTML5 The definition of 'pagehide' in that specification. |
Recommendation |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
pagehide event | Chrome ? | Edge ? | Firefox Full support 1.5 | IE ? | Opera ? | Safari ? | WebView Android ? | Chrome Android ? | Firefox Android Full support 4 | Opera Android ? | Safari iOS ? | Samsung Internet Android ? |
Legend
- Full support
- Full support
- Compatibility unknown
- Compatibility unknown
See also
onpageshow
event handler property- The
pageshow
event