HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
The onbeforeunload event fires when the document is about to be unloaded. "
The onbeforeunload
event fires when the document is about to be unloaded.
This event allows you 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. See the first example on this page.
The onbeforeunload
attribute is part of the Event Attributes, and can be used on the following element:
Elements | Event |
---|---|
<body> | onbeforeunload |
Execute a JavaScript when the page is about to be unloaded:
<body onbeforeunload="return myFunction()">
The numbers in the table specify the first browser version that fully supports the event.
Event Attribute | |||||
---|---|---|---|---|---|
onbeforeunload | Yes | Yes | Yes | Yes | 15.0 |