Window.onbeforeunload fires in IE for partial postback events

I want to warn users when updating or clicking a browser button if they have entered something in the text fields. So I used the window.onbeforeunload function to do this.

window.onbeforeunload = function () {
    if (if user hasn't entered any thing) {
        return;
    }
    return 'Entered data will be lost.';
};

this javascript code works fine in Firefox and Chrome. But in IE, this function works for buttons with partial feedback. Any solution to solve this problem in IE? Thank:)

  • This is due to an error in IE.
+5
source share
3 answers

window.onbeforeunload IE . " ". href= "javascript:...." (ASP.Net LinkButton ), IE . dirtyflag

var __ignoreDirtyFlag = false;

$(document).ready(function () {
    if ($.browser.msie) {
        $('[href^="javascript:"]').bind('click.ignoreDirtyFlag', function () {
            __ignoreDirtyFlag = true;
        });
    }
}); 

, , , href ^ = "javascript:", . , __ingoreDirtyFlag ;

window.onbeforeunload = function globalWindowUnload() {
    if (!__ignoreDirtyFlag && isDataFilled == true) {
        return "You have unsaved changes on this page. If you leave this page, those changes will be lost.";
    }
    __ignoreDirtyFlag = false;
    return;
};

- asp, , . , .

,

function foo() {
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);
}

function endRequestHandler(sender, args) {
    // Do your stuff
    if ($.browser.msie) {
        $('[href^="javascript:"]').bind('click.ignoreDirtyFlag', function () {
            __ignoreDirtyFlag = true;
        });
    }
}

body, foo(). <body onload="foo()">

IE :)

+5

`var inFormOrLink = false; var url_auth = ''; var __ignoreDirtyFlag = false;

document).ready(function () {

if ($.browser.msie) {
    $('').bind('click.ignoreDirtyFlag', function () { __ignoreDirtyFlag = true; alert("teste luiz") });

    window.onbeforeunload = function () {
        if (!__ignoreDirtyFlag) {
            return "Tem certeza que deseja encerrar a sessão TESTE LUIZ?";
        }
        __ignoreDirtyFlag = false;
        return;
    };
}
else {
    $('*').live('click', function () { inFormOrLink = true; alert("Passou aqui 1 LUIZ"); });
    $('*').bind('submit', function () { inFormOrLink = true; alert("Passou aqui 2"); });
    window.onbeforeunload = function () {
        if (!inFormOrLink) {

            if (window.location.href.indexOf("DEV2") != -1) {
                $.post("/DEV2/SSQ/AUTH/LOGOUT", null);
                return 'Tem certeza que deseja encerrar a sessão TESTE DEV2?';
            }`
0

The goal is to log out every time you close your browser or manually change the recipient's URL

var url_auth = '';var __ignoreDirtyFlag = false;$(document).ready(function () {if ($.browser.msie) {$('a').live('click', function () { __ignoreDirtyFlag = true;}); $('*').bind('submit', function () { __ignoreDirtyFlag = true; });window.onbeforeunload = function () {if (!__ignoreDirtyFlag) {if (window.location.href.indexOf("DEV2") != -1) {$.post("/DEV2/SSQ/AUTH/LOGOUT", null);return 'Tem certeza que deseja encerrar a sessão ?';}}};
0
source

All Articles