2

I have a short piece of JQuery that creates a .M3U file containing only a single string, which it then prompts the user to download. This works fine in Chrome but has no effect in Firefox, and no errors appear on the FireFox console. Can anyone help?

function playfile(filepath) {
    var file = document.createElement('a');
    file.setAttribute('href', 'data:text/plain;charset=utf-8,' + decodeURIComponent(unescape(filepath)));
    file.setAttribute('download', "Play.m3u");
    file.click();
}
John Bergqvist
  • 852
  • 13
  • 38
  • 1
    Regarding [this](http://stackoverflow.com/a/20194533/402037) answer, try adding the link to the DOM – Andreas Apr 07 '15 at 15:05
  • Can you elaborate a bit more please? I'm struggling to fit the answer in that post with mine, sorry. – John Bergqvist Apr 07 '15 at 15:07
  • 4
    Just add the link to the DOM before actually clicking it `document.body.appendChild(file); file.click();` and remove it afterwards (if needed) `document.body.removeChild(file);` – Andreas Apr 07 '15 at 15:10
  • Ahh thanks. It's working although the "from" portion in the Firefox download prompt simply says "data:" is there any way I can alter this value, either to an explicit value, or the url of the page (which is localhost)? – John Bergqvist Apr 07 '15 at 15:13
  • Sorry, but with this question/problem I can't help you... – Andreas Apr 07 '15 at 15:15

0 Answers0