Reputation: 2180
Hi friends I'm working on a static mobile site and getting stuck on a issue .The issue is I want to make download a mp3
file when user click on appropriate link. I also tried following code but it will make file open in new window and file starts playing over new tab.
I dont want to play file by click on link a want to make it download on users mobile.
Is there any wayout with using HTML5, jQuery etc.
Please help me guys.. :)
<a href="singinintherain.mp3" target="_blank"><img src="genekelly.jpg" alt="Gene_Kelly" /></a>
Upvotes: 0
Views: 633
Reputation: 309
HTML5 has a download
attribute which you can read about here.
Also you can edit the code as follows:
<a href="singinintherain.mp3" download="singinintherain.mp3"><img src="genekelly.jpg" alt="Gene_Kelly" /></a>
The download
attribute is only supported in: Firefox, Opera & Chrome and NOT IE or Safari but you can use modernizr.com
which is a plugin desgined to be placed in webpages to allow non-supporting web browsers to interpret HTML5 requests.
Visit modernizr
here.
Upvotes: 0
Reputation: 641
Use the html5 download attribute:
<a href="singinintherain.mp3" download><img src="genekelly.jpg" alt="Gene_Kelly" /></a>
See this link. Apparently, the download attribute doesn't work in ie and Safari. For those browsers, you could just direct the user to right click the link and choose 'Save as' for the file to download.
Upvotes: 2