Trigger file download on a page with content
I have seen many websites triggering a file save-as dialog开发者_运维问答 on a page with existing HTML content. How do they do this?
I know about setting the right headers such as Content-disposition etc. but when I do that, the content of the page does not load, and immediately the file download is triggered...
Make a regular HTML page, then add a META refresh that redirects to a PHP script that sends the file with a Content-Disposition
header.
For example:
<meta http-equiv="refresh" content="2;url=download.php">
I know a lot of them use a hidden iframe, the page that the iframe points towards is actually a file download.
Although there are better ways to do this, I'm sure.
精彩评论