开发者

Is it possible to send an html file with a downloadable file in one response?

Basically, I am using an iframe to download a file. I set the source of the iframe to the file I want to download. That problem isn't that I can't get a download dialog. The problem is I can't close the window after the download is started.

What I was thinking is I could send back one file with this header.

"Content-Disposition","attachment;filename=test.txt"

Then I would like to send back another HTML for the browser to display. The whole point of the second file is to close the br开发者_开发技巧owse window.

BTW: It is far to late to go away from popups.


No, you can't send both a file and a page in the same response.

If you want two responses, you have to send two requests.

Alternatively, you can start the download, then use a timeout to close the window after the download has started:

window.location.href = 'test.txt';
window.setTimeout(function(){
  window.close();
}, 100);


The whole point of the second file is to close the browse window.

You don't need this. Just setting that header on the response with the to-be-downloaded file is more than sufficient to get a Save As dialogue. You don't need to open the link in a new/blank window. Just let the link/form point to the desired URL and it'll open the Save As dialogue. The currently opened page will remain the same.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜