18

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:

enter image description here

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?

  • Internet Explorer 8+
  • Firefox 19+
  • Chrome 17+
  • Safari 5.1.9+
  • Opera 12.1
DavidPostill
  • 7,734
  • 9
  • 41
  • 60
boburShox
  • 2,630
  • 5
  • 23
  • 35

2 Answers2

3

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");
tsauerwein
  • 5,841
  • 3
  • 36
  • 49
1

There is Downloadify, which generates and force downloads files with Flash. There's also a demo available.

Or you could download the file using XHttpRequest ($.get in jQuery) and use data URIs.

Community
  • 1
  • 1
Marius
  • 309
  • 1
  • 5
  • 16