Reputation: 233
Here I have an anchor tag in my html page which will go to Google when I click. I have a jQuery function which needs to be fired when the page leaves.
$(window).unload(function(){
alert('fffffffff');
});
I found this works fine in a video tutorial. But it's not working for me. Using firefox. help
Upvotes: 4
Views: 9155
Reputation: 6124
window.onbeforeunload = function() {
return "Are you sure you wish to leave the page?";
}
Upvotes: 5
Reputation: 6554
Its working fine, you just need to remove the alert
, as some browsers don't allow alert on unload
event.
$(window).unload(function(){
console.log("hello");
});
try this http://jsfiddle.net/vyMdF/
Just run it again and you can check the console.
You can refer over here $(window).unload is not firing
Upvotes: 5