html tutorial - onpagehide Attribute in HTML - html5 - html code - html form



  • The onpagehide 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.

Syntax for onpagehide attribute in HTML:

<body onpagehide="script">

Applies to:

Elements Attribute
<body> onpagehide

Attributes Values of onpagehide attribute in HTML:

Value Description
Script The script can run on onpagehide

Sample coding for onpagehide attribute in HTML:

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

Code Explanation for onpagehide attribute in HTML:

onpagehide Attribute Code Explanation

  1. The onpagehide attribute calls the JavaScript Function onPageHide() and occurs when a user navigates away from the page.
  2. The JavaScript Function onPageHide() display an alert box with the message ”Thank you, Please Visit again.”.

Browser Support for onpagehide attribute in HTML:

Yes 11.0 Yes 5.0 Yes

Related Searches to onpagehide attribute in html