简体   繁体   中英

problem in calling cgi from javascript

I am executing a cgi file directly from javascript onclick of a button. The cgi return the doc, xls, exe etc file which in turn opens SavaAs dialog to let the client save file on his machine. Problem comes when multiple cgi files are executing in a for/while loop, It executes only the first cgi and opens the SaveAs dialog, but once the SaveAs opens it does not enter into the "for" loop again to execute another cgi which opens SaveAs dialog .

Here is the code fragment -

for(i = 0; i < dataPopup.elements['checkbox'].length; i++)      
{
    j=0;
    obj = dataPopup.elements['checkbox'];
    if(obj[i].checked)
    {
        var temp=obj[i].value;
        temp = temp.split(".");
        if(temp[1] == "txt")
        {
            saveWins[temp[1]] = setTimeout("document.location='../cgi/saveTextFile.cgi?fname=070319185708701_1'", 100);
        }
        else if(temp[1] == "pdf")
        {
            saveWins[temp[1]] = setTimeout("document.location='../cgi/savePdfFile.cgi?fname=065726729272220_1'", 100);
        }
        else if(temp[1] == "xls")
        {
            saveWins[temp[1]] = setTimeout("document.location = '../cgi/saveXlsFile.cgi?fname=288433243743'", 100);
        }
        else if((temp[1] == "doc") || (temp[1] == "docx"))
        {
            saveWins[temp[1]] = document.location = '../cgi/saveDocFile.cgi?fname='+temp[0];
        }
        saveWins[temp[1]].focus();
    }
}

Please Help.

Setting document.location replaces the current document with the new document - even if it's a download. That means there is no longer a script to continue to execute.

You'll need to set the location of an iframe instead.

RoToRa表示您应该在页面中插入一个隐藏的iFrame,然后使用window.frames[iframeName].location更改iframe的位置,而不是使用document.location。

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