简体   繁体   English

提示浏览器下载对话框

[英]prompt browser download dialogue box

Normal: <a href="/soundfile.mp3">download</a> 正常: <a href="/soundfile.mp3">download</a>

The reason I can't do this is it's on a wordpress installation with a plugin ( wpaudio ) which turns every mp3 filein the code into a mini player which when clicked streams the file. 我不能这样做的原因是它是一个带有插件( wpaudio )的wordpress安装,它将代码中的每个mp3文件转换成一个迷你播放器,当点击它时会流式传输文件。 So that link above would appear as a link, with a play button beside it, when clicked would stream the file, and not prompt the download dialogue box. 因此,上面的链接将显示为链接,旁边有一个播放按钮,单击时会流式传输文件,而不会提示下载对话框。 With 99% of the mp3 files on this site that's exactly what is needed. 这个网站上有99%的mp3文件正是我们所需要的。

However for one file, I need to enable the user to click the linked word download, and get the save or open dialogue box, along with subsequent progress bar (if enabled in his browser preferences). 但是对于一个文件,我需要让用户单击链接的单词下载,并获得保存或打开对话框,以及后续进度条(如果在他的浏览器首选项中启用)。 PHP or javascript is fine, either will do, anybody know how to get that working? PHP或javascript很好,要么会,有人知道如何工作? thanks loads, JSC 感谢负载,JSC

According to the plugin site you linked to: 根据您链接到的插件网站:

Convert all mp3 links 转换所有mp3链接
To turn every mp3 link on your blog into a player, select Convert all mp3 links in the WPaudio settings. 要将博客上的每个mp3链接转换为播放器,请选择WPaudio设置中的转换所有mp3链接。

Convert some mp3 links 转换一些mp3链接
For any mp3 link you'd like to convert to a player, add the wpaudio class like this: 对于您想要转换为播放器的任何mp3链接,请添加如下所示的wpaudio类:
<a href="http://url" class="wpaudio" >Artist - Song</a> <a href="http://url" class="wpaudio" >Artist - Song</a>

So, you probably just don't want to have to go give every link that class right? 所以,你可能只是不想去给那个类的每个链接对吗? So, use JavaScript to do it. 所以,使用JavaScript来做到这一点。 Give the links you don't want converted a class of no-wpaudio or something, and use JavaScript to add the class to all the links without the no-wpaudio class. 给你希望转换为no-wpaudio类的链接,并使用JavaScript将类添加到没有no-wpaudio类的所有链接。 Hopefully you are using jQuery: 希望你使用jQuery:

$("a[href$='.mp3']:not(.no-wpaudio)").addClass("wpaudio");

If not, what a pain, but it can be done. 如果没有,多么痛苦,但可以做到。 Let me know if you want the non-jQuery code. 如果你想要非jQuery代码,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM