【问题标题】:JavaScript exit popup function doesn't work properly in Chrome and IEJavaScript 退出弹窗功能在 Chrome 和 IE 中无法正常工作
【发布时间】:2012-05-01 19:23:34
【问题描述】:

我有一个退出弹出 js 函数,当有人试图离开页面时,它会显示一个警报并向 url 添加一些内容(并重定向)。

警报显示在所有浏览器中,但代码:

window.location.href = "?p=exit" 

在 Chrome 和 IE 中不执行。

它在 Firefox 中运行良好。当您重新加载页面时,会显示警报并修改 url。

看一下源码,很简单。

代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<script type="text/javascript">
var exit=true;
    function confirmExit()
            {
            if(exit)
            {
            window.location.href = "?p=exit";
            }
            if(exit)
            return "Wait! Don't Leave Empty Handed!\n\nThank you for taking the time to check out our offer! Before you go we have a complimentary crash to help you succeed. Click the 'Cancel' or 'Stay On This Page' button if you're interested!";
            }
</script>
</head>
<body  onbeforeunload="return confirmExit()">
</body>
</html>

【问题讨论】:

  • 请不要在您的帖子中使用签名或标语,否则它们将被删除。stackoverflow.com/faq#signatures
  • 你能在你的问题中粘贴一些相关的代码吗?

标签: javascript jquery redirect


【解决方案1】:
  • 您不能(跨浏览器)从“onbeforeunload”重定向。
  • Chrome 会阻止在“onbeforeunload”中设置的警报。

查看此答案以获取更多信息: https://stackoverflow.com/a/7080331/353710

【讨论】:

  • 链接在这种情况下没有提供任何有用的信息。
猜你喜欢
  • 2013-07-07
  • 2017-12-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-17
  • 2016-01-09
相关资源
最近更新 更多