代码可以在Chrome和Edge中使用,但不能在IE中使用-setimeout?

时间:2019-07-18 11:16:43

标签: javascript jquery html

我有以下downloadZip.html。下载适用于Chrome和Edge,但不适用于IE。该文件从jspf页面被调用如下。当我单击“下载列出的文档”时,它将调用popupDownloadWindow(),它将在plainview中打开downloadZip.html。加载时此html调用enableLink(),流程进行。由于视图是纯视图,因此只有在执行enableLink()块的情况下才首先执行(if(callerview ==“ plainview”))。不知道是否由于setTimeout()而发生这种情况。请在这里帮助我。让我知道任何信息。

function checkReturn(){
    //alert('checkReturn - sessionsNotOk global var = '+sessionsNotOk);
    if (sessionsNotOk != "DEF") {

        var docbases = sessionsNotOk.split(",");
        //alert('checkReturn - docbases arr = '+docbases+', length='+docbases.length);
        if (docbases.length == 1 && docbases[0] == "OK"){
            // All sessions are faja
            document.getElementById('divIndicator').style.display='none';
            document.getElementById('checkSession').style.display='none';
            document.getElementById('noSession').style.display='none';
            document.getElementById('dlink').style.display='inline';
            document.getElementById('dlink').style.textAlign='center';
            document.getElementById('dlink').style.display='';

        } else {
                // We need to show the sublogin dialog
                var nextDocbase = docbases[0];

                //alert("Next NOT AVAILABLE session = "+nextDocbase);
                window.opener.$('#subloginmessage').css('display','none');
                window.opener.$('#loginIndicator').css('display','none');
                window.opener.$('#sub-uid').val(window.opener.$('#user_name').text());
                window.opener.$('#sub-uid').attr('disabled','disabled');
                window.opener.$('#sub_docbase').text(nextDocbase);

                document.getElementById('checkSession').style.display='none';
                document.getElementById('noSession').style.display='inline';
                document.getElementById('noSession').style.textAlign='center';
                document.getElementById('noSession').style.display='';

                window.opener.sublogin_fw = "download";
                window.opener.sublogin_db = nextDocbase;

                window.opener.$('#sublogindialog').dialog('open');
                window.opener.$('#sublogindialog').dialog('option','title','Login to docbase: ' + nextDocbase + ' and click on Download listed documents link again!');
        }
        return;
    }
    //Check again in 0.5 second
    setTimeout("checkReturn()",500);
    //setTimeout(function() {
    //  checkReturn();
    //}, 500);

}

完整代码:

<script>
    var downloadZipChildWindow; 

    function popupDownloadWindow(){
        downloadZipChildWindow = window.open('../html/downloadZip.html?view=plainview','downloadwindow','width=300,height=200,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=no');
    }
</script>

<a id='download_link' class='download_link' href="#" onClick="popupDownloadWindow()">Download listed documents</a>



<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Download documents as Zip file</title>
    <script type="text/javascript" src="../js/jquery-1.6.1.min.js" ></script>
    <style type="text/css">
        p
        {
            font-family:"Verdana";
            font-size:small;
        }
        a
        {
            font-family:"Helvetica";
            font-size:small;
        }
    </style>
    <script type="text/javascript">

var lastParam;
var sessionsNotOk = "DEF";
var callerView;

function getParam( paramName )
{
    paramName = paramName.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&]"+paramName+"=([^&#]*)";
    var regex = new RegExp( regexS );
    var results = regex.exec( window.location.href );
    if( results == null )
        return "";
    else
        return results[1];
}

/*
 * Checks the return from ajax servlet call "../downloadzip?ask=isSRPsessionsOK&packageIDs="+pIDs".
 * Called always right after checkDocbaseSessions() call.
 */
function checkReturn(){
    //alert('checkReturn - sessionsNotOk global var = '+sessionsNotOk);
    if (sessionsNotOk != "DEF") {

        var docbases = sessionsNotOk.split(",");
        //alert('checkReturn - docbases arr = '+docbases+', length='+docbases.length);
        if (docbases.length == 1 && docbases[0] == "OK"){
            // All sessions are faja
            document.getElementById('divIndicator').style.display='none';
            document.getElementById('checkSession').style.display='none';
            document.getElementById('noSession').style.display='none';
            document.getElementById('dlink').style.display='inline';
            document.getElementById('dlink').style.textAlign='center';
            document.getElementById('dlink').style.display='';

        } else {
                // We need to show the sublogin dialog
                var nextDocbase = docbases[0];

                //alert("Next NOT AVAILABLE session = "+nextDocbase);
                window.opener.$('#subloginmessage').css('display','none');
                window.opener.$('#loginIndicator').css('display','none');
                window.opener.$('#sub-uid').val(window.opener.$('#user_name').text());
                window.opener.$('#sub-uid').attr('disabled','disabled');
                window.opener.$('#sub_docbase').text(nextDocbase);

                document.getElementById('checkSession').style.display='none';
                document.getElementById('noSession').style.display='inline';
                document.getElementById('noSession').style.textAlign='center';
                document.getElementById('noSession').style.display='';

                window.opener.sublogin_fw = "download";
                window.opener.sublogin_db = nextDocbase;

                window.opener.$('#sublogindialog').dialog('open');
                window.opener.$('#sublogindialog').dialog('option','title','Login to docbase: ' + nextDocbase + ' and click on Download listed documents link again!');
        }
        return;
    }
    //Check again in 0.5 second
    //setTimeout("checkReturn()",500);
    setTimeout(function() {
        checkReturn();
    }, 500);
}

function enableLink(){
    callerView = getParam("view");
    var pkgType = "";
    var params = "";
    var packageIDs = "";

    if (callerView == "plainview") {

        pkgType = window.opener.$('#hiddenPkgType').attr('value');
        // Check available sessions
        if (pkgType == 'srp'){
            document.getElementById('dlink').style.display='none';
            document.getElementById('checkSession').style.display='inline';
            document.getElementById('checkSession').style.textAlign='center';
            document.getElementById('checkSession').style.display='';
            packageIDs = window.opener.$('#hiddenSRPIDs').attr('value');
            checkDocbaseSessions(packageIDs);
            checkReturn();
        }
        params = window.opener.$('#hiddenDownloadParams').attr('value');

    } else if (callerView == "packagedetailview") {

        pkgType = window.opener.$('#hiddenPkgType_DetailedPackageView').attr('value');
        if (pkgType == "" || pkgType == null) {
            alert("Still loading data, window will be closed. Please click on download button after all data have been loaded on the page!");
            window.close();
        }
        params = window.opener.$('#hiddenDownloadParams_DetailedPackageView').attr('value');

    } else if (callerView == "SRP_packagedetailview") {

        // Prepare/check remote sessions
        packageIDs = window.opener.$('#SRP_DPV_pkgIDs').attr('value');
        checkDocbaseSessions(packageIDs);
        checkReturn();

        pkgType = 'srp';
        if (pkgType == "" || pkgType == null) {
            alert("Still loading data, window will be closed. Please click on download button after all data have been loaded on the page!");
            window.close();
        }
        params = window.opener.$('#hiddenDownloadParams_SRP_DetailedPackageView').attr('value');

    } else if (callerView == "SRP_checkstatusview") {

        // Prepare/check remote sessions
        packageIDs = window.opener.$('#SRP_CSV_pkgIDs').attr('value');
        checkDocbaseSessions(packageIDs);
        checkReturn();

        pkgType = 'srp';
        if (pkgType == "" || pkgType == null) {
            alert("Still loading data, window will be closed. Please click on download button after all data have been loaded on the page!");
            window.close();
        }
        params = window.opener.$('#hiddenDownloadParams_SRP_CheckStatusView').attr('value');

    }

    if (pkgType == 'nlp' || pkgType == 'monnlp') {
        document.getElementById('download_zip_stdfilenames_nlp_country').style.display='inline';
        document.getElementById('download_zip_stdfilenames_nlp_product').style.display='inline';
        document.getElementById('download_zip_stdfilenames_nlp_country').style.textAlign='center';
        document.getElementById('download_zip_stdfilenames_nlp_product').style.textAlign='center';
        document.getElementById('download_zip_stdfilenames').style.display='none';                                      
    } else if (pkgType == 'clp') {
        document.getElementById('download_zip_stdfilenames_nlp_country').style.display='none';
        document.getElementById('download_zip_stdfilenames_nlp_product').style.display='none';
        document.getElementById('download_zip_stdfilenames').style.display='inline';    
        document.getElementById('download_zip_stdfilenames').style.textAlign='center';
    } else if (pkgType == 'ipl') {
        document.getElementById('download_zip_stdfilenames_nlp_country').style.display='none';
        document.getElementById('download_zip_stdfilenames_nlp_product').style.display='none';
        document.getElementById('download_zip_stdfilenames').style.display='inline';    
        document.getElementById('download_zip_stdfilenames').style.textAlign='center';
    }

    //Defined as global
    zipParamsImp = params + "&filename=import";
    zipParamsStd = params + "&filename=standard";
}

function showIndicator(param){
    document.getElementById('divIndicator').style.display='inline';
    document.getElementById('divIndicator').style.textAlign='center';
    document.getElementById('divIndicator').style.display='';
    document.getElementById('dlink').style.display='none';

    var parameters = "";
    if (param == 'import'){
        parameters = zipParamsImp;
    } else if (param == 'standard') {
        parameters = zipParamsStd;
    } else if (param == 'standard_nlp_country') {
        parameters = zipParamsStd + "_nlp_country";
    } else if (param == 'standard_nlp_product') {
        parameters = zipParamsStd + "_nlp_product";
    }
    lastParam = param;  
    postwith("../downloadzip",parameters);
}

function postwith (to, params) {
    var myForm = window.opener.document.createElement("form");
    myForm.method="post" ;
    myForm.action = to ;
    myForm.style.display = 'none';

    jQuery.each(params.split('&'), function(){
        var pair = this.split('=');
        var myInput = window.opener.document.createElement("input") ;
        myInput.setAttribute("name", pair[0]) ;
        myInput.setAttribute("value", pair[1]);
        myForm.appendChild(myInput);
    });
    var lastInput = window.opener.document.createElement("input") ;
    lastInput.setAttribute("name", "download_token_value_id") ;
    lastInput.setAttribute("value", "");
    myForm.appendChild(lastInput);

    window.opener.document.body.appendChild(myForm) ;
    myForm.submit();
    window.opener.document.body.removeChild(myForm) ;

    //setTimeout("checkProgress()",1000);
    setTimeout(function(){
        checkProgress();
    },1000);
}

/*
 * Checks return from servlet call "../downloadzip?ask=isready" -> ask whether DownloadAsZipServlet
 * has finished its work or not. If finished, close this popup.
 */
function checkProgress(){
    window.focus();
    $.ajax({
        type: "GET",
        url: "../downloadzip?ask=isready",
        dataType: "text",
        //dataType: "script",
        //timeout: 2000,
        success: function(results)
        {   
            // Normal flow
            //var result = eval('('+results+')');
            var currParams = window.opener.$('#hiddenDownloadParams').attr('value');
            //After closing DPV and clicking on Download Listed Documents button, we have to remove caller param, because there is no caller.
            //Caller exists only if openPackage function called, and Download is on a DPV page.
            //If we do not remove caller param, then exception occurs.

            var callerPrefix = currParams.substring(0,currParams.indexOf('&'));
            if (callerPrefix.indexOf('caller=') > -1) {
                window.opener.$('#hiddenDownloadParams').attr('value',currParams.replace(callerPrefix+'&',""));
            } else {
                // No caller param found
            }

            if (results.indexOf('window.close()') > -1) {
                window.close();
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){
            window.top.document.location.href = "../jsp/logout.jsp?msg=Application error (HTTPREQ quicksearch download documents). You have been logged out!";
        }
    });
}

 /*
  * In case of SRP - checks whether sessions for all required docbases are available.
  * It is needed, because SRP package documents can be located in different docbases.
  */
function checkDocbaseSessions(pIDs){
    sessionsNotOk = "DEF";
    $.ajax({
        type: "GET",
        url: "../downloadzip?ask=isSRPsessionsOK&packageIDs="+pIDs,
        dataType: "text",
        success: function(results)
        {   
            //alert(results);
            if ($.trim(results) == 'OK'){
                //alert("Sessions are OK!");
                sessionsNotOk="OK";
            } else {
                sessionsNotOk=results;
                //alert("Sessions are NOT OK! - "+sessionsNotOk);

            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){
            window.top.document.location.href = "../jsp/logout.jsp?msg=Application error (HTTPREQ quicksearch download documents). You have been logged out!";
        }
    });
}
</script>
</head>
<body style="background-color: #ffffff; font-family: Verdana, Helvetica; font-size: x-small;" onload="enableLink();">
    <div id="divIndicator" style="display: none"><br />
        <p>Zip file creation in progress. This may take a few minutes, please wait and do not navigate away or start another query!</p>
        <br />
        <br />
        <span id="qIndicator"> <img border="0" src="../img/indicator.gif"></span>
        <br />
        <br />
    </div>
    <p style="text-align: center">Download listed documents</p>
    <div id="dlink" style="text-align: center">
        <a href="#" style="text-align: center" id='download_zip_impfilenames' onClick="showIndicator('import')">With import file names</a> 
        <br />
        <a href="#" style="text-align: center" id='download_zip_stdfilenames' onClick="showIndicator('standard')">With standard file names</a>
        <a href="#" style="display: none; text-align: center" id='download_zip_stdfilenames_nlp_country' onClick="showIndicator('standard_nlp_country')">With standard file names starting with country</a>
        <a href="#" style="display: none; text-align: center" id='download_zip_stdfilenames_nlp_product' onClick="showIndicator('standard_nlp_product')">With standard file names starting with product</a>
    </div>
    <div id="noSession" style="display: none">
    <p>Some required sessions are unavailable. Please login to the docbase!</p>
    </div>
    <div id="checkSession" style="display: none">
    <p>Checking required sessions in progress. Please wait...</p>
    <br />
    <span id="qIndicator"> <img border="0" src="../img/indicator.gif"></span>
    <br />
    </div>
</body>
</html>

0 个答案:

没有答案