Alternative Jquery Library To Triger Beforeunload/unload Event
edit: As my question seems unclear - all i want is to add confirm() message whenever the user leaves the page by closing browser/typing new link/clicking existing link I've read a
Solution 1:
beforeunload
events are a little odd. Most browsers won't allow you to trigger a confirm dialogue from the handler since that would allow the site to continuously pop up confirm dialogues rather than navigating away from the page. Instead, you should return the message you want to display, for example:
$(window).on('beforeunload', function(e) {
var msg = 'You are about to leave the page. Continue?';
(e || window.event).returnValue = msg; //IE + Gecko
return msg; //Webkit
});
If you want to run additional javascript after the resultant dialogue has exited, add an onunload
listener.
EDIT
As is pointed out in the comments, these events differ from browser to browser. For example, the latest version of gecko (firefox) does not allow custom messages.
Post a Comment for "Alternative Jquery Library To Triger Beforeunload/unload Event"