HTML onpagehide attribute

HTML onpagehide attribute: This attribute occurs when the user is redirecting away from a webpage. The onpagehide event is frequently used instead of the onunload event, as the onunload event causes the page is not being cached.

HTML onpagehide attribute

This attribute supports the <body> element.

Syntax: <body onpagehide=”script”>

Example:



<!DOCTYPE html>
<html>
    <head>
        <title>Freshersnow onpagehide Attribute</title>
    </head>
    <body onpagehide="onPageHide()">
        <h1><Freshersnow onpagehide Attribute></h1>    
        <script>
            function onPageHide() {
                alert ("Thank you, Please Visit again.");
            }
        </script>
    </body>
</html>