繁体   English   中英

浏览器关闭事件调用时如何重定向其他页面

[英]how to redirect in other page when browser close event called

当浏览器关闭时,我想在另一个页面中重定向。 我的代码如下:

<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?";
  }
}

但是,当我单击浏览器的关闭按钮时,我看到系统确认消息,而且在Mozilla中也没有弹出页面打开的提示。 我该如何解决这个问题?

谢谢

页面的代码摘录。

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;

简短答案:

如果您不阻止它,则您的代码将完美运行。

长答案:

是一个有效的示例-几乎和您一样(请看一下源代码)。

但是:仅当您通常在FF中禁用弹出窗口阻止程序(或创建规则以允许该URL弹出窗口)时,此方法才有效。

我确定您的代码无法正常工作的原因是激活的弹出窗口阻止程序,它显示了这个漂亮的黄色“网站试图打开弹出窗口”,由于该站点已关闭,因此未向您显示警告消息(因此,您将无法点击“允许来自此站点的弹出窗口”)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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