使用javascript开始和停止嵌入html的音乐仅在IE中有效 [英] Start and stop for a embeded music in html using javascript works only in IE

查看:101
本文介绍了使用javascript开始和停止嵌入html的音乐仅在IE中有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已使用以下代码将音乐嵌入网页中:

I have embeded a music in a webpage using this code:

<embed src="upload/gnossiennes.mp3" autostart="true" loop="true" hidden="true"></embed>

然后我正在使用此javascript代码启动/停止它:

Then I am using this javascript code to start/stop it:

<script type="text/javascript">
    function play() {
        document.embeds[0].play();
    }
    function stop() {
        document.embeds[0].stop();
    }
</script> 

<span><a href="#" onClick="play();">START</a></span>
<span><a href="#" onClick="stop();">STOP</a></span>

仅在IE中有效,而在Chrome,FireFox和Opera中不起作用。可能是什么问题? (这是页面中唯一的嵌入内容,因此我猜 document.embeds [0] 仅指此嵌入内容,不应该是问题所在,除非此数组不存在于其他浏览器!

This works only in IE but not in Chrome, FireFox and Opera. What can be the problem? (this is the only embed in the page so I guess document.embeds[0] is only referring to this embed and shouldnt be the problem, unless this array does not exist in other browsers!

推荐答案

很好地引用一个< embed> 对于更多嵌入标签的潜在使用是致命的。如果您只是想开始停止,则只需创建并删除它作为DOM元素。这是一个类似问题并具有相同的解决方案

Well referencing one <embed> could be fatal for prospective uses of more embed tags. If you simply want to start and stopit then simply create and remove it as a DOM element. Here was a similar question and had the same solution

这篇关于使用javascript开始和停止嵌入html的音乐仅在IE中有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆