繁体   English   中英

从JavaScript调用CGI的问题

[英]problem in calling cgi from javascript

我直接从按钮的javascript onclick执行cgi文件。 CGI返回doc,xls,exe等文件,依次打开SavaAs对话框,让客户端将文件保存在其计算机上。 当多个cgi文件在for / while循环中执行时出现问题,它仅执行第一个cgi并打开SaveAs对话框,但是一旦SaveAs打开,它就不会再次进入“ for”循环来执行另一个cgi来打开SaveAs对话框对话。

这是代码片段-

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();
    }
}

请帮忙。

设置document.location会将当前document.location替换为新文档-即使是下载的文档。 这意味着不再有脚本可以继续执行。

您需要设置iframe的位置。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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