简体   繁体   中英

onBeforeUnload/unload

In Javascript, I keep seeing posts about how one should not try to use onBeforeUnload or unload() in jQuery, citing security issues. Could someone explain in greater detail what these issues are?

On that note, I have also found that neither of these work in any browser I've tried. Even something simple like this:

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

Is this intentional, or no?

You might have mixed it up with the issues concerning usability??

I use it as native js

window.onunload = function(e) {
   return 'Dialog text here.';
};

You con't use an Alert inside your function for simple raison that onunload is a pop-up so the display your text (HELLO) just but it in the return or try this:

window.addEventListener("beforeunload", function(event) {
                    event.returnValue = 'hello';
            });   

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