Web/API/Window/pagehide event

From Get docs


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

Examples

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 StandardThe definition of 'pagehide' in that specification. Living Standard Initial specification.
HTML5The definition of 'pagehide' in that specification. Recommendation

Browser compatibility

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
pagehide event Chrome

Full support 3

Edge

Full support 12

Firefox

Full support Yes

IE

Full support Yes

Opera

Full support Yes

Safari

Full support Yes

WebView Android

Full support ≤37

Chrome Android

Full support 18

Firefox Android

Full support Yes

Opera Android

Full support Yes

Safari iOS

Full support Yes

Samsung Internet Android

Full support 1.0

Legend

Full support  
Full support


See also