What is the usage of the onbeforeunload event in JavaScript?

HTMLJavascriptProgramming Scripts

If you want to trigger an event before the document is loaded, then use the onbeforeunload event.


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

<!DOCTYPE html>
   <body onbeforeunload="return myFunction()">

      <a href="https://www.qries.com">Click to open Qries</a>
         function myFunction() {
            return "Working with onbeforeunload event";
Published on 26-Feb-2018 15:17:51