1

I have some content on the page which appears when page is loading :

$(document).ready(function() {
   $("#1").show(function(){
     $("#2").slideDown(function(){
     });    
   });
});

I was wondering if there is a chance to to the same thing but before leave the page.

user1806258
  • 87
  • 2
  • 11

4 Answers4

1

Not really, as it would allow you to prevent the user from leaving the page. You probably would not want a website that did not allow you to close it when you wanted to, right?

jwueller
  • 30,582
  • 4
  • 66
  • 70
1

You can't. You can only trigger a dialog before a page unloads.

See:

How can I override the OnBeforeUnload dialog and replace it with my own?

Community
  • 1
  • 1
Diodeus - James MacFarlane
  • 112,730
  • 33
  • 157
  • 176
1

Actually, there is no event that triggers that.

However, you can use those animations when someone clicks away to another page (using onclick). That is, navigates to another page by clicking a link/div on your current page. Then you can redirect them.

Eisa Adil
  • 1,743
  • 11
  • 16
1

$( window ).unload(function() { }

http://api.jquery.com/unload/

unload event is fired by many cases, i would suggest to test thoroughly.

I too will prefer not to do such things when user wants to leave page, not good UI practice unless its a necessary requirement.

make sure the loaded resources of the page are still resent otherwise Leeds to exceptions.

harshal
  • 592
  • 6
  • 25