2010-07-23 13 views
0

我正在執行一個cgi文件,直接從javascript onclick的按鈕。 cgi返回doc,xls,exe等文件,然後打開SavaAs對話框讓客戶端將文件保存在他的機器上。當多個CGI文件中執行 問題而來的,是對/ while循環,它僅執行第一CGI和打開另存爲對話框,但一旦另存爲打開它並沒有進入「for」循環再執行這將打開另一個CGI另存爲對話框。從javascript調用cgi的問題

下面是代碼片段 -

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

請幫助。

回答

1

設置document.location用新文檔替換當前文檔 - 即使是下載。這意味着不再有腳本可以繼續執行。

您需要改爲設置iframe的位置。

+0

感謝您的回覆。 我的理由,爲什麼它不工作,但什麼你的意思「你需要設置一個iframe的位置,而不是」。你在使用哪種iframe? – Neha 2010-07-26 07:33:53

0

RoToRa意味着,而不是使用document.location,你應該在頁面中插入一個隱藏的iframe和更改使用window.frames[iframeName].location iframe的位置。