0

How to download a PDF file using file URL. I am tried many eg, but no luck. All are opening the file in the new tab. anyone have any idea about this.

Eg code

var link = document.createElement('a');
link.href = file_path;
link.download = file_path.substr(file_path.lastIndexOf('/') + 1);
link.click();
byteC0de
  • 5,153
  • 5
  • 33
  • 66
  • https://stackoverflow.com/questions/3802510/force-to-open-save-as-popup-open-at-text-link-click-for-pdf-in-html – Vladimir M May 14 '18 at 12:52

2 Answers2

1

You can make use of the download attribute like so:

<a href="file link" download target="_blank">Click here to download</a>
Jesse
  • 3,522
  • 6
  • 25
  • 40
Shoaib
  • 822
  • 1
  • 15
  • 27
0

Can i use: https://caniuse.com/#search=download

HTML5 over link add attribute download like this example:

<a href="assets/pdfs/MYFILETODOWNLOAD.pdf" download>
THE PDF DOWNLOAD IT !
</a>