HTML5 embed tag - event attributes not firing (one

2019-07-22 11:47发布

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条回答
甜甜的少女心
2楼-- · 2019-07-22 12:19

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.

查看更多
登录 后发表回答