View Full Version : mp3 download in javascript?

08-30-2006, 06:42 AM
how can I make it so when a person clicks on a link attached to an mp3 file it displays the download dialog allowing them to save it to their harddrive as opposed to just playing the file through quicktime. I need it to be xhtml strict compliant as well.

08-30-2006, 10:33 AM
There's a way of managing it. But you have to alter the HTTP headers by using PHP, for instance...

I mean: it's just needed you make the browser open a new window in a Strict-XHTML compliant way (it's easy, there are many threads talking about that in this forum) when the user click the anchor you put into your webpage. The address you have to show must be a page made just for downloading - no XHTML tag into.

Its headers must be something like this:

Content-type: audio/mpeg;
Content-Disposition: attachment; filename="yourmp3.mp3"

Then, it's just needed you put the mp3 file be directly the output, into the HTTP body. And you're gone.
I said: I know the way to making it in PHP but I suppose it's not the right forum here to speak about this method...

I hope I've told you useful stuff!