What is the usage of onunload event in JavaScript?

HTMLJavascriptProgramming Scripts

The unload event trigger when you unload (or refresh) a page. You can try to run the following code to learn how to implement onunload event in JavaScript:

Example

<!DOCTYPE html>
<html>
   <body onunload="newFunc()">
      <p>Close the page and see what happens!</p>
      <p>This event may give unexpected results.</p>
      <script>
         function newFunc() {
            alert("Thank you!");
         }
      </script>
   </body>
</html>
raja
Published on 26-Feb-2018 10:56:51
Advertisements