jQuery onClick() IE 中的音效和重定向

jQuery onClick() Sound Effect and Redirection in IE

本文关键字:音效 重定向 IE onClick jQuery      更新时间:2023-09-26

因此,与我和老板的建议相反,一位客户坚持认为,当他们点击他们网站主导航上的所有链接时,他们希望在链接实际将 suer 带到新页面之前,对他们网站主导航上的所有链接产生"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时,在我的WinXP机器上与IE8一起工作,但声音在运行IE9的老板Win7机器上不起作用。那么,造成这种情况的原因可能是什么呢? 只是IE是IE,还是我搞砸了?

通过添加另一行来解决,例如 beow,但链接到 wma 声音

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