Tutorial :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 means that instead of using document.location you should insert a hidden iFrame in your page and change the location of the iframe using window.frames[iframeName].location.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »