Download Link not working in html

35,960

Solution 1

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

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

Solution 2

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");

Solution 3

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.

Solution 4

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.

Share:
35,960
Java Student
Author by

Java Student

Updated on July 09, 2022

Comments

  • Java Student
    Java Student almost 2 years

    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