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>
How to execute a JavaScript when the page is about to be unloaded | HTML Window Event Attributes |
HTML onafterprint Event Attribute | HTML Window Event Attributes |
HTML onbeforeprint Event Attribute | HTML Window Event Attributes |
HTML onbeforeunload Event Attribute | HTML Window Event Attributes |
HTML onerror Event Attribute | HTML Window Event Attributes |
HTML onhashchange Event Attribute | HTML Window Event Attributes |
HTML onload Event Attribute | HTML Window Event Attributes |
HTML onoffline Event Attribute | HTML Window Event Attributes |
HTML ononline Event Attribute | HTML Window Event Attributes |
HTML onpageshow Event Attribute | HTML Window Event Attributes |
HTML onresize Event Attribute | HTML Window Event Attributes |
HTML onunload Event Attribute | HTML Window Event Attributes |
Type
: |
html |
Category
: |
Web Tutorial |
Sub Category
: |
HTML Window Event Attributes |
Uploaded by
: |
Admin |