2009-08-24 94 views
1

我有这样的代码块:JQuery的DOM操作和window.onbeforeunload在Internet Explorer

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操作时会引发这个事件。

有没有人知道这个解决方法?

非常感谢,

查尔斯

回答

1

试试这个, “onunload的” 应该FF工作。

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