Javascript DOM onpagehide Event

Introduction

Execute a JavaScript when the user is navigating away from a webpage.

The onpagehide event occurs when the user is navigating away from a webpage.

To find out if a page is loaded directly from the server or if the page is cached, use the persisted property of the PageTransitionEvent object.

This property returns true if the page is cached by the browser, and false otherwise.

Due to different browser settings, this event may not always work as expected.

In JavaScript:

object.onpagehide = function(){
       myScript};

In JavaScript, using the addEventListener() method:

object.addEventListener("pagehide",
       myScript);

The addEventListener() method is not supported in Internet Explorer 8 and earlier versions.

Bubbles: No
Cancelable: No
Event type: PageTransitionEvent
Supported HTML tags: <body>



PreviousNext

Related