i am trying to make a download link in html that is given like this for a PDF Book
<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
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. 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
你可以试试这个
<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.
Here is the support across the different browsers: http://caniuse.com/#feat=download .
The HTML5 download attribute is only supported by Chrome and firefox... Try this :
<a href="download.php" target="_blank"> Download </a>
Download.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.
Thanks.
如果您想在当前网站完好无损的情况下在下一个选项卡中下载 pdf,请使用以下代码:
<a href="/pdf/book.pdf" download="book.pdf" target="_blank">Download </a>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.