revision:
This attribute fires when the document is about to be unloaded. This event allows to display a message in a confirmation dialog box to inform the user whether he/she wants to stay or leave the current page. The default message that appears in the confirmation box, is different in different browsers.
However, the standard message is something like "Are you sure you want to leave this page?". You cannot remove this message. However, you can write a custom message together with the default message.
The "onbeforeunload attribute" is part of the event attributes and can be used on the following element:<body>.
<body onbeforeunload="script"></body>
This attribute contains single value script and it runs when onbeforeunload event called.
Close this window, press F5 or click on the link below to invoke the onbeforeunload event.
click here to go to my website<body onbeforeunload="return changeFunction()"> <p class="spec">Close this window, press F5 or click on the link below to invoke the onbeforeunload event.</p> <a href="https://www.lwitters.com">click here to go to my website</a> </body> <script> function changeFunction() { return "You are leaving this page to go to my website. Do you want to do this?"; } </script>