问题描述
< a href =sample.pdftarget =_ blank>下载< / a>
如果我点击下载按钮,这个目标空白将打开一个新窗口。
但我需要它提示保存此文件的对话框。我怎样才能做到这一点?
这是你无法完全控制HTML本身的东西。
如果用户使用带有PDF阅读功能的浏览器插件)和相应的设置打开浏览器中的PDF文件,PDF将以这种方式打开。
由于您的<$ c
如果您使用的是HTML5,则可以使用:
< a href =sample.pdfdownload =sample.pdf>下载< / a>
如果您有一个您可以控制的后端服务,或者您觉得像摆弄Web服务器,你总是可以寻找设置正确的 Content-Disposition
。看到这个问题的。
<a href="sample.pdf" target="_blank">Download</a>
If I click Download button, this target blank is opening a new window.
But I need it to prompt a dialog for saving this file. How can I achieve this?
This is something that you cannot absolutely control with HTML itself.
If the user is having a browser with PDF reading capabilities (or a plugin) and the corresponding settings to open PDF files in-browser, the PDF will open like that.
The PDF opens in a new tab simple because of your target="_blank"
, which has nothing to do with a download prompt.
If you are using HTML5 you can use the download attribute:
<a href="sample.pdf" download="sample.pdf">Download</a>
If you have a back-end service which you can control or you feel like fiddling with your Web Server, you can always look for setting the right Content-Disposition
. See this SO question for some nice discussion on Content-Disposition.
这篇关于如何强制下载文件提示,而不是使用HTML在浏览器中显示它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!