onbeforeunload event occurs when the document is about to be unloaded.
This event enables a web page to trigger a confirmation dialog asking the user if they really want to leave the page. If the user confirms, the browser navigates to the new page, otherwise it cancels the navigation.
The default message that appears in the confirmation box, is different in different browsers. However, the standard message is something like "Changes you made may not be saved.". This message cannot be overwritten.
Note: Some browsers allow you to customize the message to the user. However, this is deprecated and no longer supported in most browsers.
onbeforeunload Event as Attribute
Using Event Listener
onbeforeunload Event as Property
Using addEventListener() Method
Note: The addEventListener() method is not supported in Internet Explorer 8 and below.
Please do google search for:
Join Our Channel
This channel is primarily useful for Full Stack Web Developer.