Remove BODY onunload Event After Page Has Loaded

July 26th, 2012 - Posted by Steve Marks to (X)HTML / CSS, Javascript / jQuery, Web Development.

The onunload can be used to perform an action or to call a function when the user leaves a webpage.

There are scenarios however when you might want to remove this action after the page has loaded. Take a look at the simple example below where I present a very basic HTML page containing an onunload attribute on the <body> tag, then also a link that, when clicked, removes this onunload event:

<html>
<body onunload="alert('Unloading Body');">

<a href="#" onclick="document.body.onunload = null;">Click me to remove body onunload</a>

</body>
</html>
This entry was posted on Thursday, July 26th, 2012 at 8:36 pm by +Steve Marks and is filed under (X)HTML / CSS, Javascript / jQuery, Web Development. You can follow any responses to this entry through the RSS 2.0 feed.
Comments...

Fear not, we won't publish this

Comments (0)

No comments have been left yet. Be the first