What is the usage of onpagehide event in JavaScript?

HTMLJavascriptProgramming Scripts

The onpagehide event triggers in JavaScript when a user leaves the page and decides to move to another. Some examples include age refresh, a link is clicked, etc.


You can try the following code to learn how to implement onpagehide event in JavaScript.

<!DOCTYPE html>
   <body onpagehide="newFunc()">
      <p>Close the page and see what happens!</p>
         function newFunc() {
            alert("Thank you!");
Published on 26-Feb-2018 15:22:17