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.


<!DOCTYPE html>
   <body onunload="newFunc()">
      <p>Close the page and see what happens!</p>
      <p>This event may give unexpected results.</p>
         function newFunc() {
            alert("Thank you!");
Updated on 21-May-2020 07:51:06