HTML5 embed tag - event attributes not firing (onended, onpause etc)

蓝咒 提交于 2019-12-12 18:28:42

问题


I've searched for many hours trying to find a solution to this problem. I have a HTML5 web page with a background sound file that plays automatically when the page loads, and I'm trying to get a function to run when the sound file finishes playing. I've isolated the code I'm using into a test file to ensure nothing else is causing the problem. The sound plays fine in Firefox (which I'm using to test). From the many solutions I've tried, it seems as though the event attributes in the embed tag simply aren't firing at all.

Here is the test HTML page I'm using (tried putting HTML in here but it wouldn't show up properly, I know it's probably a noob error but I'm in a hurry with this):

Testpage

As you can see the message function works fine, as the "TEST" link indicates when clicked. But the messages for the media events don't appear.

If anyone can help me with this, I'd be most grateful as it's for a time-critical company project. I'd be happy to try alternative solutions to the event attributes, as long as I can get my own Javascript function to run on the sound file reaching its end, I'll be happy!!

Thanks!

  • Billy

回答1:


Since you're using HTML5, it would be better to use the <audio> tag rather than <embed>. This works fine in my example:

http://jsfiddle.net/u6dbV/

You can include HTML here, but it has to be marked up as code or it'll get stripped out.



来源:https://stackoverflow.com/questions/10667808/html5-embed-tag-event-attributes-not-firing-onended-onpause-etc

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