javascript - IE中的jQuery onClick()声音效果和重定向

标签 javascript jquery internet-explorer audio embed

因此,在我和老板的建议下,一个客户坚持认为,在链接实际将用户带到新页面之前,当他们单击它们时,希望在其网站主导航上的所有链接上都具有“boing”的音效。

为此,在将用户发送到新页面之前,单击链接时,我使用jQuery将embed标记附加到主体。这是我正在使用的jQuery:

<script type="text/javascript">
    (function($) {
        $(document).ready(function() {
            $("#menu_container a").click(function(e) {
                e.preventDefault();
                var url = $(this).attr('href');

                $('body').append('<embed src="/media/sounds/boing_spring.mp3" autostart="true" width="1" height="1" id="LegacySound" enablejavascript="true">');

                setTimeout(function() {
                    window.location = url;
                }, 500);

                setTimeout();
            });
        });
    })(jQuery)
</script>

因此,这似乎可以在OSX / Ubuntu和Windows的Safari / Chrome / FF / Opera中正常运行。

但是,当谈到Internet Explorer时,在装有IE8的WinXP机器上就可以正常工作,但声音在运行IE9的老板Win7机器上却不起作用。那么,这可能是什么原因呢?是jsut IE是IE,还是我搞砸了?

最佳答案

通过添加另一行(如一个蜂鸣声)来解决,但改为链接到wma声音

$('body').append('<embed src="/media/sounds/boing_spring.mp3" autostart="true" width="1" height="1" id="LegacySound" enablejavascript="true">');

关于javascript - IE中的jQuery onClick()声音效果和重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11969900/

相关文章:

javascript - 如何从 `setTimeout` 回调中获取返回值?

jquery - WooThemes - Flexslider : Height of flex-viewport

javascript - 是否可以在构造函数之外定义特权方法?

javascript - 'let' 是否覆盖全局声明并抛出 ReferenceError?

javascript - 使用 D3 访问链接的 SVG 的元素 ID

html - 为什么@font-face 在 ie10 中如此困难

css - 3d 变换 IE10

javascript - jquery datatable 以大写显示数据

jquery - 防止 jQuery 中的滚动事件

html - IE8 为非显示元素保留空间