Share

January 29, 2009

Replace Body onunload using jQuery unload function

Sometime you want a run a function when the user navigates away from the page. The HTML way is to use the following code

<body onunload="myAction();">

Here is how you do the same with jQuery lib.
$(window).unload(function() { myAction() });

enjoy