how to redirect in other page when browser close event called
I want to redirect in another page when browser is closed. My code is following:
<script language="Javascript">
var needToConfirm = true;
window.onbeforeunload = confirmExit;
function confirmExit(){
if (needToConfirm){
my_window = window.open ("1.html","mywindow1","status=1,width=350,height=150");
return "You have attempted to leave this page. If you have made any changes "
+"to the fields without clicking the Save button, your changes will be "
+"lost. Are you sure you want to exit this page?";
}
}
But when I am clicking on close button of browser, I am seeing an system confirmation message and I am also not getting 开发者_JAVA技巧pop up page opening in mozilla. How will i resolve this problem?
Thanks
Code excerpt from this page.
function goodbye(e) {
if(!e) e = window.event;
//e.cancelBubble is supported by IE - this will kill the bubbling process.
e.cancelBubble = true;
e.returnValue = 'You sure you want to leave?'; //This is displayed on the dialog
//e.stopPropagation works in Firefox.
if (e.stopPropagation) {
e.stopPropagation();
e.preventDefault();
}
}
window.onbeforeunload=goodbye;
short answer:
your code works perfectly if you wouldn't have blocked it.
long answer:
this is a working example - and it's almost the same like yours (take a look at the sourcecode).
but: this works only if you're generally disabling the popup-blocker in FF (or create a rule to allow popups from that URL).
i'm sure the reason your code isn't working is the activated popup-blocker, wich shows this nice, yellow "site tries to open a popup"-warning wich isn't shown to you because the site is closed (so, you can't klick on "allow popups from this site").
精彩评论