问题
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 stop
it 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