0

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.

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the reply. I got the reason as why it is not working, but what do you mean by "You'll need to set the location of an iframe instead." Which iframe are you taking about.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.