Start and stop for a embeded music in html using javascript works only in IE

怎甘沉沦 提交于 2019-12-11 00:41:03

问题


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

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

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>

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!


回答1:


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



来源:https://stackoverflow.com/questions/9750010/start-and-stop-for-a-embeded-music-in-html-using-javascript-works-only-in-ie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!