Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/447.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Internet Explorer中的JQuery DOM操作和window.onbeforeunload_Javascript_Jquery_Html_Asp.net Mvc_Dom - Fatal编程技术网

Javascript Internet Explorer中的JQuery DOM操作和window.onbeforeunload

Javascript Internet Explorer中的JQuery DOM操作和window.onbeforeunload,javascript,jquery,html,asp.net-mvc,dom,Javascript,Jquery,Html,Asp.net Mvc,Dom,我有这个代码块: window.onbeforeunload = function(){ <% if (Session["DisableExitConfirmation"] == null || !(bool)Session["DisableExitConfirmation"]) { %> if (isDirty) return '<%= Html.EncodeJsString(Html.Resource("profile

我有这个代码块:

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")) %>');
            <% } %>
        };
window.onbeforeunload=函数(){
如果(isDirty)返回“”;
如果(isDirty)警报(“”);
};
我正在页面中进行一些DOM操作,向UL添加一个LI元素。在执行此操作时,我将isDitry设置为true,并且在Internet Explorer中启动window.onbeforeunload。我希望只有在用户刷新页面时才会引发它,或者在isDirty为true时退出它

在firefox中,我没有这种行为

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

有人知道这方面的解决方法吗

非常感谢

查尔斯试试这个,“onUnLoad”应该适用于FF

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

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

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