如何在html中创建下载链接? [英] How can I create download link in html?
问题描述
感谢Advance。
这个答案是过时的。我们现在按照此处所述的
下载
属性。
如果通过下载链接表示指向要下载的文件的链接,请使用
< a href =http://example.com/files/myfile.pdftarget =_ blank>下载< / a>
target = _blank
将会创建一个新的浏览器窗口出现在下载开始之前。当浏览器发现资源是文件下载时,该窗口通常会关闭。
请注意,浏览器已知的文件类型(例如JPG或GIF图像)通常会在浏览器中打开。
您可以尝试发送正确的标题来强制下载,例如: 此处。 (需要服务器端脚本或访问服务器设置)。
I have a basic idea of HTML. I want to create the download link in my sample website, but I don't have idea of how to create it. How do I make a link to download a file rather than visit it?
Thanks in Advance.
This answer is outdated. We now have the
download
attribute as described here.
If by "the download link" you mean a link to a file to download, use
<a href="http://example.com/files/myfile.pdf" target="_blank">Download</a>
the target=_blank
will make a new browser window appear before the download starts. That window will usually be closed when the browser discovers that the resource is a file download.
Note that file types known to the browser (e.g. JPG or GIF images) will usually be opened within the browser.
You can try sending the right headers to force a download like outlined e.g. here. (server side scripting or access to the server settings is required for that.)
这篇关于如何在html中创建下载链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!