• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2229
  • Last Modified:

Can JavaScript Force Download?

I understand that I can force a file to be saved instead of opened the server sends out appropriate headers.

But can this be done client-side with JavaScript?

<a href="pdf.pdf" onclick="forceDownload(pdf.pdf);return false;">Force Download of PDF (do NOT open in browser)</a>

Open in new window

2 Solutions
You cannot use javascript so force download a file. The response headers required for force download cannot be added using javascript and has to be done using a server side script.
You cannot do it through Javascript. But you can have an intermediate Server page which can access the download file on your behalf, and can write the Forced download entries in the response headers.

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now