1

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.To 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.

3 Answers 3

2

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']

Sign up to request clarification or add additional context in comments.

1 Comment

Oops... I didn't see them in the first reading but now I see them... Maybe the window part?
2
$(window).bind("unload", function(){
alert(123);
});

worked for me :)

Comments

0
$(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.

1 Comment

what do you mean with 'Move to other page' do you CLOSE this page? or not? do you browse to another page? or are you just changing tabs in the browser? Did you include the jQuery js file? perhaps you have any other javascript errors which prevent this one from running...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.