简体   繁体   中英

Jquery beforeunload event not firing in any browser

It's not firing when I close the browser. I have researched the issue a lot and found similar kinds of solution, but it is still not working.

$(document).ready(function(){
    $(window).bind("beforeunload", function() { 
        return confirm("Do you really want to close?"); 
    })
});

You can achieve this by using below piece of code.

$(window).on('beforeunload', function(){
  return confirm("Do you really want to close?"); 
});

If you want to perform some other things after user clicks yes, you can write that under

  $(window).on('unload', function(){
 //DoSomething
 });

I normally just use this:

(function($){
    $(window).on("beforeunload", function() { 
        return true;
    })
})(jQuery);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM