简体   繁体   中英

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. I set isDitry to true when I am doing this and the window.onbeforeunload is raised when I am in Internet Explorer. I want it to be raised only when the user refreshes the page or quit it when isDirty is true.

In firefox I don't have this behavior.

I don't understand why this event is raised whend I do DOM manipulation with JQuery.

Does anyone know a workaround for this?

Thanks a lot,

Charles

试试这个,“ onUnLoad”应该对FF有效。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM