开发者

Trigger file download on a page with content

开发者 https://www.devze.com 2023-01-01 21:00 出处:网络
I have seen many websites triggering a file save-as dialog开发者_运维问答 on a page with existing HTML content. How do they do this?

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.

0

精彩评论

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