[英]javascript force play sound instead of download
I recently made a soundboard about hearthstone , but when I click on the card(image) on my localhost it plays the sound(like intended) , while when I click on the card(image) on my online hosting it downloads the file. 我最近制作了一个有关炉石的音板,但是当我单击本地主机上的卡(图像)时 ,它会播放声音(如预期的声音) ,而当我单击在线主机上的卡(图像)时 ,它将下载文件。
Is there a way to make sure it always plays the sound? 有没有办法确保它总是播放声音?
<script type="text/javascript">
$(document).ready( function() {
$('.card').click(function(){
$('#wrap').html('<embed id="embed_player" src="'+$(this).attr('name')+'" autostart="true" hidden="true"></embed>');
});
});
</script>
<div id="pictures">
<img name="media/Sir-finly.mp3" src="media/Sir finly.gif" class="card" id="sir-finly" alt="" />
<img name="media/ShifterZerus.mp3" src="media/ShifterZerus.gif" class="card" id="shifterzerus" alt="" />
<div id="wrap"></div>
</div>
hope you guys can help me. 希望你们能帮助我。
You can use audio tag instead of embed . 您可以使用音频标签而不是embed 。
Example: http://codepen.io/anon/pen/LxaLMO 示例: http : //codepen.io/anon/pen/LxaLMO
HTML HTML
<div id="pictures">
<img name="http://developer.mozilla.org/@api/deki/files/2926/=AudioTest_(1).ogg" src="http://megaicons.net/static/img/icons_sizes/8/178/256/numbers-1-filled-icon.png" class="card" id="sir-finly" alt="" />
<img name="http://developer.mozilla.org/@api/deki/files/2926/=AudioTest_(2).ogg" src="http://www.freeiconspng.com/uploads/number-2-two-icon-13.png" class="card" id="shifterzerus" alt="" />
<audio id="player" src="" autoplay></audio>
JS JS
$(document).ready( function() {
$('.card').click(function(){
$('#player').attr('src', $(this).attr('name'));
});
});
Documentation: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio 文档: https : //developer.mozilla.org/en-US/docs/Web/HTML/Element/audio
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.