12

As the title says, I'd like to download a mp3-file instead of playing it in Firefox.

I do it like this:

<a href="http://test.com/path/to/my/file.mp3" download></html>

In all other browsers the file is downloaded, only Firefox starts playing the audio file instead of asking me if I would like to save it to my hard disk.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
enne87
  • 2,221
  • 8
  • 32
  • 61

4 Answers4

15

Write this

<a href="http://test.com/path/to/my/file.mp3" download></html> WRONG

should be

<a href="http://test.com/path/to/my/file.mp3" download="file.mp3">download</a>
Snake Eyes
  • 16,287
  • 34
  • 113
  • 221
  • I've added this dynamically (with javascript) to all my .mp3 links and it doesn't work in FireFox 37.0.1 – Miss A Apr 22 '15 at 18:49
  • 2
    Maybe when you wrote the answer it was wrong, but actually it is correct: ` If the attribute has a value, it is used as the pre-filled file name in the Save prompt` https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a – abumalick Jun 26 '18 at 23:16
  • 4
    it doesn't work in last Chrome 67.0.3396.99. File opens in new tab. – mathewsun Jul 16 '18 at 11:01
  • It works fine (with or without specifying a filename (so this answer is wrong)) in Chrome 86. – Quentin Nov 20 '20 at 12:20
  • @Quentin did you see the date when answer was posted? – Snake Eyes Nov 20 '20 at 16:47
  • @SnakeEyes — Yes. It is out of date and deserves to be edited to be representative of the state of play now the attribute has standardised. (I came across it because it was being used to support an incorrect answer on another question. The authority of the green tick lends it credence even though it is now wrong.) – Quentin Nov 20 '20 at 16:49
3

Tested 8/18, Firefox correctly handles a simple download attribute. The accepted and second-ranked answers are wrong, at least as of now.

So, simply,

<a href="http://test.com/path/to/my/file.mp3" download></a>

will work, and if you want to control what the file is downloaded as, you give download a value:

<a href="http://test.com/path/to/my/file.mp3" download="use-this-name.mp3"></a>

That is why Chrome (or any modern browser) will download it as "true.mp3" if you try to use download="true" instead of a simple download to force the file download.



Also, note that <a></html> in the question isn't valid, and could have possibly caused a problem at the time if that's not just a typo.

  • None of solutions work. At least when target="_blank" attribute set that can't be avoided in most scenarios of usage. – Arsenii Fomin Oct 04 '18 at 12:45
  • 2
    Update: looks like solution doesn't work with cross-origin links as mentioned here: https://stackoverflow.com/questions/3802510/force-to-open-save-as-popup-open-at-text-link-click-for-pdf-in-html – Arsenii Fomin Oct 04 '18 at 12:50
1

This is the correct way to force the download:

<a href="http://test.com/path/to/my/file.mp3" download="true">download</a>

NB: it will work on Firefox only if the file is located on the same domain unfortunately, cf. https://bugzilla.mozilla.org/show_bug.cgi?id=874009

Rigoni Jr
  • 35
  • 3
1

I used <a href="http://test.com/path/to/my/file.mp3" download >download</a> If you use the download="true" inside the anchor This will result in the renaming of the file name to true.mp3 in chrome an firefox as mention above.

sagiet
  • 58
  • 4