![]() |
Definition and UsageThe 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. Note: In Firefox, only the default message will be displayed (not the custom message (if any)). Applies toThe
Browser SupportThe numbers in the table specify the first browser version that fully supports the event. |
Example:
HTML
<!DOCTYPE html>
<html>
<body onbeforeunload="return myFunction()">
<p>Close this window, press F5 or click on the link below to invoke the onbeforeunload event.</p>
<a href="https://horje.com">Click here to go to horje.com</a>
<script>
function myFunction() {
return "Write something clever here...";
}
</script>
</body>
</html>
html onbeforeunload attribute |
How to Execute a JavaScript when the page is about to be unloaded | HTML Attribute |
Read Full: | HTML Attribute |
Type: | Develop |
Category: | Web Tutorial |
Sub Category: | HTML Attribute |
Uploaded by: | Admin |
Views: | 96 |
Reffered: https://www.w3schools.com/tags/ref_attributes.asp