简体   繁体   English

下载链接在 html 中不起作用

[英]Download Link not working in html

i am trying to make a download link in html that is given like this for a PDF Book我正在尝试在 html 中制作一个下载链接,该链接是为 PDF 书提供的

<a href="http://www.mydomain.org/pdf/book.pdf" target="_blank"> Download </a>

but problem is that when download link is clicked it opens online version of pdf , does not offer download , i did google and found same way to add download link , any one can guide me with it please whats wrong here但问题是,当点击下载链接时,它会打开 pdf 的在线版本,不提供下载,我用谷歌搜索并找到了添加下载链接的相同方法,任何人都可以指导我,请问这里有什么问题

As of late 2018, clicking the link won't trigger a download if the resource to be downloaded wasn't served from the same origin or same server.截至 2018 年底,如果要下载的资源不是来自同一来源或同一服务器,则单击该链接将不会触发下载。 Apparently, this is restriction is a security measure.显然,这是限制是一种安全措施。

You can download the content in browser and make it downloadable, you can check the below url您可以在浏览器中下载内容并使其可下载,您可以查看以下网址

https://medium.com/charisol-community/downloading-resources-in-html5-a-download-may-not-work-as-expected-bf63546e2baa https://medium.com/charisol-community/downloading-resources-in-html5-a-download-may-not-work-as-expected-bf63546e2baa

你可以试试这个

<a href="/pdf/book.pdf" download="book.pdf">Download </a>

HTML5 defines the download attribute , which forces the browser to prompt the user a download dialog for the resource instead of navigate to it. HTML5 定义了download属性,它强制浏览器提示用户下载资源的对话框,而不是导航到它。

Here is the support across the different browsers: http://caniuse.com/#feat=download .以下是对不同浏览器的支持: http : //caniuse.com/#feat=download

The HTML5 download attribute is only supported by Chrome and firefox... Try this : HTML5 下载属性仅受 Chrome 和 firefox 支持...试试这个:

<a href="download.php" target="_blank"> Download </a>

Download.php下载.php

header("Content-disposition: attachment; filename=http://www.mydomain.org/pdf/book.pdf");
header("Content-type: application/pdf:");
readfile("http://www.mydomain.org/pdf/book.pdf");

Its not the problem with your script, instead its your browser that has pdf plug-in and displays you the content file directly.You can just save the page (Press CTRL+S) and it would be saved as .PDF file.这不是你的脚本的问题,而是你的浏览器有 pdf 插件并直接向你显示内容文件。你可以保存页面(按 CTRL+S),它会被保存为 .PDF 文件。

Thanks.谢谢。

如果您想在当前网站完好无损的情况下在下一个选项卡中下载 pdf,请使用以下代码:

 <a href="/pdf/book.pdf" download="book.pdf" target="_blank">Download </a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM