开发者

unload event when using master page

开发者 https://www.devze.com 2023-01-14 18:56 出处:网络
In my project i have used master page.In one particular page , i want a function to be executed on page unload(javascript event) event of that particular page.T开发者_如何转开发o achieve this i have w

In my project i have used master page.In one particular page , i want a function to be executed on page unload(javascript event) event of that particular page.T开发者_如何转开发o achieve this i have written

    $('body').bind('unload',function()  
{  
alert('hello');  
} );     

But this is not working.This function is not getting called when i move to other page. How should i achieve this.


Well, I suppose its a problem when writing the question but your code should be:

 $(window).bind('unload',function()
 {
      alert('hello');
 });

You are missing the ending ); and the event should be bound to the window...

[Edit: Added the bind to the window instead of 'body']


$(window).bind("unload", function(){
alert(123);
});

worked for me :)


$(document).ready(function(){

    $(window).unload( function () {
       alert("Bye now!"); 
    } );

});

try this. the document.ready function runs on pageload. so your bind will execute and is should work.

0

精彩评论

暂无评论...
验证码 换一张
取 消