在 IE 上停止 BGSOUND 元素?
我已将背景音乐添加到我正在构建的网站中(别杀了我)。
而在 IE 中,该元素称为 BGSOUND,我尝试使用一个按钮来暂停
音乐,按钮会删除整个元素并重新添加它,但是
结果删除该元素只会重新启动 IE 的音乐。
如何通过 javascript 停止 BGSOUND 元素播放音乐?
当前代码:
<!--[if IE]>
<BGSOUND id="bgmusic" SRC="<?php echo bloginfo('stylesheet_directory'); ?>/bgmusic.mp3" LOOP="true">
<![endif]-->
当我触发命令时 document.getElementById('bgmusic').stop()
我得到对象不支持属性或方法“停止”
I've added background music to a website i'm building (don't kill me).
Whereas in IE the element is called BGSOUND, I tried to have a button to pause
the music, the button removes the entire element and re-adds it, however
turns out removing the element only restarts the music for IE.
How do I stop music being played by the BGSOUND element via javascript?
Current code:
<!--[if IE]>
<BGSOUND id="bgmusic" SRC="<?php echo bloginfo('stylesheet_directory'); ?>/bgmusic.mp3" LOOP="true">
<![endif]-->
When I fire the command document.getElementById('bgmusic').stop()
I get Object doesn't support property or method 'stop'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
一个丑陋的解决方法是设置
音量
到-10000:An ugly work around is by setting the
volume
to -10000:我在客户页面上遇到了类似的情况。
我发现 删除 src 属性 bgsound 元素是避免 IE 中重新启动音乐问题的最佳方法。
I had a similar situation with the page of a client.
I found that removing the src property of the bgsound elements is the best way to avoid the restart music problem in IE.
我建议使用 Flash。您不仅可以更好地控制音乐,而且还可以跨浏览器工作。如今,拥有 Flash 播放器的用户多于 IE。
I suggest using Flash instead. Not only will you have more control over the music, but it will work across browsers too. Today more users have Flash player than IE.
当用户按下
暂停
时:删除元素并将其存储在变量中当用户按下
Play
时:从变量中获取元素并将其添加到 DOMWhen user presses
Pause
: Remove the element and store it in a variableWhen user presses
Play
: Get the element from the variable and add it to the DOM我建议使用 SoundManager。
它将尽可能使用 HTML5 音频,否则将回退到 Flash。它有一个统一且简单的API。
I recommend using SoundManager.
It will use HTML5 audio when it can, and will otherwise fall back to Flash. And it has a unified and easy API.
如果要执行 stop(),只需将 src 设置为空值即可。适用于 IE11(也可使用 IE8 仿真)。
If you want to perform a stop(), you can just set src to an empty value. Works in IE11 (with IE8 emulation as well).