0

I have this inside my $(document).ready function:

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

check_saved() just triggers a dialog box that asks the user if they would like to save their form data before leaving the page. The browser displays the dialog box but then navigates away instantly. I want the browser to wait until the users clicks a button, just like it would for a normal alert(). How do I do this? Also, chrome seems to ignore the unload event? Any ideas?

tshepang
  • 12,111
  • 21
  • 91
  • 136
kmb64
  • 1,513
  • 2
  • 17
  • 29

1 Answers1

0

How the user navigate to another page? Let say user is doing it by clicking some link on the page. then you can check in that action instead of page unload.

$('a').click(function(e){
 if(  check_saved()!=true){

    e.preventDefault();
    return false;   
  }

});
Jayantha Lal Sirisena
  • 21,216
  • 11
  • 71
  • 92
  • The unload event should be triggered when the user clicks a link, clicks forward or back, closes the window or tries to go to a new page in the address bar. So i would want to have the same result for any of these possibilities – kmb64 Nov 21 '11 at 03:35
  • Then it would be better if you look at the duplicate question ,I think you can find the answer from that . – Jayantha Lal Sirisena Nov 21 '11 at 03:40
  • by looking at this answer http://stackoverflow.com/questions/6063522/jquery-beforeunload id dont think there is anyway you can pause unload, may just have to use something other than a jquery dialog. – kmb64 Nov 21 '11 at 03:49