I am fully aware that there are many debates(and solutions) out there in terms of downloading files in javascript/jQuery, such as iFrame
, jQueryPlugin
. However, I am more interested in a kind of built-in facilities like download
attribute of <a>
in HTML5. The problem is that it supports a couple of browsers:
That is how I want to download files, without creating frames or using any plugins. The questions is are there any other cross browser built-in(say, easier or cleaner) ways to do it?
The download attribute only works for same-originl URLs. So if the href is not the same origin as the site, it won't work. In other words, you can only download files that belongs to that website. This attribute follows the same rules outline in the same-origin policy.
You might want to try FileSaver.js which has support for all modern browsers.
var blob = new Blob(["Hello, world!"], {type: "text/plain;charset=utf-8"});
saveAs(blob, "hello world.txt");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With