How to download a file without using <a> element with download attribute or a server?

guest271314 picture guest271314 · Aug 2, 2016 · Viewed 17.5k times · Source

According to caniuse the download attribute of <a> element is supported at Microsoft Edge build 10547+, but not IE or Safari.

How to download a file object without using <a> element with download attribute set or a server?

Answer

Leo Farmer picture Leo Farmer · Aug 2, 2016

There are a number of ways of triggering a download. Following are a few:

Use a form:

<form method="get" action="mydoc.doc">
<button type="submit">Download</button>
</form>

Use javascript:

<button type="submit" onclick="window.open('mydoc.doc')">Download</button>