【问题标题】:do not display pop up window while navigating to another page导航到另一个页面时不显示弹出窗口
【发布时间】:2014-10-04 10:11:41
【问题描述】:

在我的页面中,仅当我要关闭浏览器/选项卡时才会显示确认弹出窗口。它适用于我的页面,但它也会在我导航到另一个页面时询问。我想要在导航到另一个页面时关闭选项卡而不是弹出窗口。任何人都可以帮助我。 这是代码。

var PreventExitPop = false;
function ExitPop() { 
    if(PreventExitPop == false) {     
        PreventExitPop=true;
        window.alert("hi!\n\click ok to go on  next page");     
        var frm = document.forms['exitpopform'];    
        frm.action = 'deals.html';     
        frm.submit();     
        scroll(0, 0);     
        return "\n\n\n***************************************\n\n"; 
    }
}  
window.onbeforeunload = ExitPop;
</SCRIPT>
<form id='exitpopform' method='post' action='#'>
  <input type='hidden'  value='' />
</form>

【问题讨论】:

    标签: javascript jquery


    【解决方案1】:

    试试下面的代码。

    <script type="text/javascript"> $(document).ready(function () { $("a").click(function () { window.onbeforeunload = null; }); $(window).bind("beforeunload", function () { return confirm("Do you really want to close?"); }); }) </script>

    • 当在整个网站上单击任何anchor 标签时,以上代码将为onbeforeunload 设置NULL
    • 如果用户关闭浏览器/选项卡,则会引发 onbeforeunload 功能,并显示带有警告消息的弹出窗口。
    • 对于这个功能,您必须将 JQuery 引用添加到您的 HTML 页面的 &lt;head&gt; 标签中,如下所示。

    &lt;script src="your folder name/Javascript/jquery-1.8.2.js" type="text/javascript"&gt;&lt;/script&gt;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-27
      • 2023-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-08
      • 2020-12-02
      相关资源
      最近更新 更多