【发布时间】: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