Skip to content Skip to sidebar Skip to footer

Any Way To Mimic The Download Attribute Of An Anchor Tag?

Solution 1:

I'm not aware of any Javascript function or setting that lets you change the filename when downloading, or any that imitates the download attribute on <a> tags.

In a similar question, this answer by user3758133 outlines a workaround where you programmatically create a link, attach the proper download attribute and trigger a click:

("#downloadbutton").click(function() {
  //var content = content of file;var dl = document.createElement('a');
  dl.setAttribute('href', 'data:text/csv;charset=utf-8,' + encodeURIComponent(content));
  dl.setAttribute('download', 'filename.txt');
  dl.click();
});

Post a Comment for "Any Way To Mimic The Download Attribute Of An Anchor Tag?"