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>