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();
1

2 Answers 2

1

You can make use of the download attribute like so:

<a href="file link" download target="_blank">Click here to download</a>
Sign up to request clarification or add additional context in comments.

Comments

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>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.