I am getting server side URL to my HTML,on click of that URL PDF file is opening in browser itself,Since the PDF is larger Size I want to force the user to download it(saveas pop up) Please help me
我正在获取服务器端URL到我的HTML,点击那个URL PDF文件在浏览器本身打开,因为PDF是更大的尺寸我想强迫用户下载它(saveas弹出)请帮助我。
4 个解决方案
#1
6
You don't need javascript to do this. In a modern browser you can simply do <a href="somepathto.pdf" download="filename">
你不需要javascript来实现这一点。在现代浏览器中,只需执行
Related post:
相关文章:
- How to force files to open in browser instead of download (pdf)?
- 如何强制文件在浏览器中打开而不是下载(pdf)?
#2
5
You can use the HTML5 attribute download :
您可以使用HTML5属性下载:
<a href="link" download="filename"/>
You can also make a PHP page that will read the PDF and force the download, by using these functions :
你也可以制作一个PHP网页,阅读PDF并强制下载,使用以下功能:
header('Content-Type: application/pdf');
header('Content-disposition: attachment; filename=filename.pdf');
exit(readfile(yourPDF));
(PHP is useful if you want to prevent the users to delete the download attribute, but it may be too much)
(如果您想防止用户删除下载属性,PHP是有用的,但是它可能太多了)
#3
3
Use the download
attribute:
使用下载属性:
<a download="file.pdf">Link</a>
https://html.spec.whatwg.org/multipage/semantics.html#attr-hyperlink-download
https://html.spec.whatwg.org/multipage/semantics.html attr-hyperlink-download
#4
0
try this
试试这个
> <FilesMatch "\.(?i:pdf)$"> ForceType application/octet-stream
> Header set Content-Disposition attachment </FilesMatch>
#1
6
You don't need javascript to do this. In a modern browser you can simply do <a href="somepathto.pdf" download="filename">
你不需要javascript来实现这一点。在现代浏览器中,只需执行
Related post:
相关文章:
- How to force files to open in browser instead of download (pdf)?
- 如何强制文件在浏览器中打开而不是下载(pdf)?
#2
5
You can use the HTML5 attribute download :
您可以使用HTML5属性下载:
<a href="link" download="filename"/>
You can also make a PHP page that will read the PDF and force the download, by using these functions :
你也可以制作一个PHP网页,阅读PDF并强制下载,使用以下功能:
header('Content-Type: application/pdf');
header('Content-disposition: attachment; filename=filename.pdf');
exit(readfile(yourPDF));
(PHP is useful if you want to prevent the users to delete the download attribute, but it may be too much)
(如果您想防止用户删除下载属性,PHP是有用的,但是它可能太多了)
#3
3
Use the download
attribute:
使用下载属性:
<a download="file.pdf">Link</a>
https://html.spec.whatwg.org/multipage/semantics.html#attr-hyperlink-download
https://html.spec.whatwg.org/multipage/semantics.html attr-hyperlink-download
#4
0
try this
试试这个
> <FilesMatch "\.(?i:pdf)$"> ForceType application/octet-stream
> Header set Content-Disposition attachment </FilesMatch>