[英]JQuery DOM manipulation and window.onbeforeunload in Internet Explorer
I have this code block: 我有以下代码块:
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")) %>');
<% } %>
};
I am doing some DOM manipulation in the page, adding a LI element to a UL. 我正在页面中进行一些DOM操作,将LI元素添加到UL中。 I set isDitry to true when I am doing this and the window.onbeforeunload is raised when I am in Internet Explorer. 当我这样做时,我将isDitry设置为true,而当我在Internet Explorer中时,会引发window.onbeforeunload。 I want it to be raised only when the user refreshes the page or quit it when isDirty is true. 我希望仅当用户刷新页面或在isDirty为true时退出页面时才引发它。
In firefox I don't have this behavior. 在Firefox中,我没有这种行为。
I don't understand why this event is raised whend I do DOM manipulation with JQuery. 我不明白为什么使用JQuery进行DOM操作时会引发此事件。
Does anyone know a workaround for this? 有谁知道解决方法?
Thanks a lot, 非常感谢,
Charles 查尔斯
试试这个,“ onUnLoad”应该对FF有效。
<body onunload="s();" onbeforeunload="s();">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.