Internet Explorer calling [removed] on window.open and AJAX calls

后端 未结 8 1548
刺人心
刺人心 2021-01-04 11:21

Ok, I have spent a while on this problem and this is what I have gathered:

  1. If you make an AJAX call in IE7 and you have a window.onbeforeunload function spe

8条回答
  •  遥遥无期
    2021-01-04 11:51

    I had the same problem, in my case all request come from ajax call, this simplify the solution, because when I fixed the porblem with standard button I did a recursive function to redirect all onclick to my centralized function an then dispath the rigth click. I am copying the solution for ajax call suporting href problem too. This solution avoid to return to previous page. Put the code inside a file named backbutton,js Any comment write to mparma@usa.net with subject: javascript backbutton

    
    
    
    
    
    
    var returningAddress = "http://my returning address"
    
    
    var backButtonMessage = "Using the browser's Back button may cause a loss in data. Please use the Back and Continue buttons at the bottom of the form."
    
    
    
    var backButtonPressed = 1;    
    
    
    var onbeforeunloadeventFired = 0;
    
    
    var backtoLogin = 0;
    var DoPostBackWithOptionsHook = null;
    var DoPostBackHook = null;
    
    
    
    if (window.name == ""){
        
        window.name = "L0001";
    }
    else { 
        if (window.name == "L0000_back"){
            
            setBackButton(0);
            window.name = "";
    
            
            window.location.href = returningAddress;
        }
        else {
            if (window.name.indexOf("_back") > 4){
                
    
                
                var sLastValue = modifynamevalue(0);    
    
                
                var iCountBack = -(sLastValue * 1);
                if (backtoLogin == 1) {iCountBack++;};
    
                if (window.history.length - 2 < -iCountBack) {
                    iCountBack = -(window.history.length - 2);
                }
    
                
                window.name = "L0000_back";             
                setBackButton(0);
    
                
                window.history.go(iCountBack);
            }
            else {
                
                var sLastValue = modifynamevalue(+1);
                window.name = "L" + sLastValue;
            }
        }
    }
    
    
    
    $(document).ready(function(){
        if (typeof(Sys) == "object") {
            Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequest);
            Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequest);
    
            window.onbeforeunload = onbeforeunloadEvent;
            window.onunload = unloadEvent;
            DoPostBackWithOptionsHook = WebForm_DoPostBackWithOptions;
            WebForm_DoPostBackWithOptions = WebForm_DoPostBackWithOptionsHook;
    
            doPostBackHook = __doPostBack;
            __doPostBack =  __doPostBackHook;
    
        }
    
        });
    
    function WebForm_DoPostBackWithOptionsHook(options) {
        setBackButton(0);
        return DoPostBackWithOptionsHook(options)
    }
    
    function __doPostBackHook(eventTarget, eventArgument) {
        if (backButtonPressed == 1) {
            setBackButton(0);
        }
        return doPostBackHook(eventTarget, eventArgument)
    } 
    
    function beginRequest(sender, args) {
        setBackButton(0);
        
        onbeforeunloadeventFired = 1;
    }
    
    
    function endRequest(sender, args) {
        onbeforeunloadeventFired = 0;
        setBackButton(1);
    }
    
    
    function unloadEvent(evt) {
        
        if ((backButtonPressed == 1) && (onbeforeunloadeventFired == 1)) {
            
            var sLastValue = modifynamevalue(-1);
            window.name = "L" + sLastValue + "_back";
        }
    
        if (DoPostBackWithOptionsHook !== null) {
            WebForm_DoPostBackWithOptions = DoPostBackWithOptionsHook;
        };
    
        if (doPostBackHook !== null) {
            __doPostBack = doPostBackHook;
        };
    }
    
    
    function onbeforeunloadEvent(evt) {
        onbeforeunloadeventFired = 1;
        if (backButtonPressed == 1) {
            return backButtonMessage;
        };
    }
    
    
    
    function setBackButton(value){
        if (value == 0) {
            backButtonPressed = 0;
        }
        else {
            if (onbeforeunloadeventFired == 0) {
                backButtonPressed = 1;
            }
        }
    }
    
    
    
    function modifynamevalue(iIncrement){
        var iCount = (window.name.substring(1, 5) * 1) + iIncrement;
    
        if (iCount < 0) {
            iCount = 0;
        }
    
        var sNewValue = iCount.toString();
    
        sNewValue = "0000".substring(0, 4 - sNewValue.length) + sNewValue;
        return sNewValue;
    }
    

提交回复
热议问题