Force download of a pdf file for google chrome - Javascript

Viewed 30

I have a problem where Google Chrome automatically opens pdf files instead of downloading them.

I need to be able to force this download with js so that the script then accesses another page.

1 Answers

This is a simple html5 solution:

<a href="https://where.you.hosted/your.pdf" download="filename.pdf" target="_blank">Download</a>

Note that IE still doesn't support this. But should be enough if you just want to support modern browsers.

Related