HTML onpagehide Event Attribute

Description

The event attribute onpagehide is triggered when a user leaves the page.

There are several ways to leave a page. For example, by clicking on a link, refreshing the page, submitting the form, closing the browser window, etc.

The onpagehide event is sometimes used instead of the onunload event.

Syntax

<element onpagehide="script">

Values

  • scriptThe name of the script to use when the event has been triggered.

Example

<!DOCTYPE HTML>
<html>

<body onpagehide="onPageHide()">
<p>
Note: Due to various browser settings, this event may not always work as expected..<p/>    
<script>
function onPageHide() {
   alert ("Thanks, please come back again.");
}
</script>
</body>

</html>

Supported Tags

<body>

Browser Support

Desktop
Explorer Edge Chrome Firefox Opera Safari
??????
Tablets / Mobile
Android Chrome Firefox Opera Safari Samsung
??????