window unload not work

+2 Hitesh Kushwah · July 24, 2015
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript" src="jq.js"></script>
</head>
<body>
 <a href="http://www.google.co.uk">Google.com</a>
<script type="text/javascript">

$(window).unload(function(){
alert("You wanna leave");
});
</script>

</body>
</html>

Post a Reply

Replies

Oldest  Newest  Rating
0 Brian Nyaundi · July 27, 2015
i think you wanted to check if a user is leaving the page.. in that case use 

window.onbeforeunload = function(){
return "You wanna leave";
};
0 Hitesh Kushwah · July 27, 2015
thnx buddy...:)
0 Mahmoud Atwa · July 26, 2015
it is 'window.onload()' not 'window.unload()'.....
  • 1

Javascript

106,991 followers
About

A scripting language that is added to standard HTML to create interactive effects, apps, games for the browser.

Links
Moderators