【问题标题】:JQuery DOM manipulation and window.onbeforeunload in Internet ExplorerInternet Explorer 中的 JQuery DOM 操作和 window.onbeforeunload
【发布时间】:2009-08-24 15:06:27
【问题描述】:

我有这个代码块:

window.onbeforeunload = function(){
            <% if (Session["DisableExitConfirmation"] == null || !(bool)Session["DisableExitConfirmation"]) { %>
                if (isDirty) return '<%= Html.EncodeJsString(Html.Resource("profile_unsavedchanges")) %>';
            <% } else { %>
                if (isDirty) alert('<%= Html.EncodeJsString(Html.Resource("profile_unsavedchanges")) %>');
            <% } %>
        };

我正在页面中进行一些 DOM 操作,将 LI 元素添加到 UL。我在执行此操作时将 isDitry 设置为 true,当我在 Internet Explorer 中时会引发 window.onbeforeunload。我希望仅在用户刷新页面或 isDirty 为 true 时退出页面时才引发它。

在 Firefox 中我没有这种行为。

我不明白为什么当我使用 JQuery 进行 DOM 操作时会引发此事件。

有人知道解决方法吗?

非常感谢,

查尔斯

【问题讨论】:

    标签: javascript jquery html asp.net-mvc dom


    【解决方案1】:

    试试这个,“onUnLoad”应该适用于FF。

    <body onunload="s();" onbeforeunload="s();">
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-26
      • 1970-01-01
      • 1970-01-01
      • 2012-06-07
      • 1970-01-01
      • 2011-03-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多