I have a scenario where if the user tries to close the current browser window then he should be displayed a confirm box. If he confirms to close the window then this window should close and opening the new window with different url.
I tried use the following code by which I’m able to show the confirm box but I’m unable to figure out how to open the new window if user confirms to close the current.
var preventUnloadPrompt;
$('a').live('click', function () { preventUnloadPrompt = true; });
$('form').live('submit', function () { preventUnloadPrompt = true; });
$(window).bind("beforeunload", function () {
if (preventUnloadPrompt)
{ return; }
else {
return confirm("quit??");
}
});
Any type of help is appreciated.
Thanks.
When a window closes, everything, absolutely everything associated with that window whether visible or not … pending javascript code, stuff on screen, etc. vanishes and that includes the very scripts that are in the middle of execution – poof – gone nada, basically canceling, aborting, halting, stopping any running script.
The temporal sequencing requires that, except for closing a window, all other user initiated operations be completed first.
example:
The links can be preconditioned with
if(confirm("quit??")){ ... }tested with:
Bookmark:
Open a new browser window on close of current window if user confirms to close current window