JS 实现兼容浏览器报警提示声音

来源:csdn博客 分类: 文章浏览史 发布时间:2020-12-02 20:00:50 最后更新:2020-12-02 浏览:703
转载声明:
本文为摘录自“csdn博客”,版权归原作者所有。
温馨提示:
为了更好的体验,请点击原文链接进行浏览
摘录时间:
2020-12-02 20:00:50
<!DOCTYPE HTML>
    <head>
        <title>JS实现报警提示音</title>
        <meta http-equiv="content-type" content="text/html;charset=UTF-8">
        <script src="./jquery.min.js"></script>
        <script type="text/javascript">
            function playSound() {
                var borswer = window.navigator.userAgent.toLowerCase();
                if(borswer.indexOf('ie') >= 0) {
                    var strEmbed = '<embed name="embedPlay" src="./1.mp3" autostart="true" hidden="true" loop="false" />';
                    if($('body').find('embed').length <= 0) {
                        $('body').append(strEmbed);
                    }
                    var embed = document.embedPlay;
                    //浏览器不支持audio,则使用embed播放
                    embed.volume = 100;
                } else {
                    //非IE内核浏览器
                    var strAudio = '<audio id="audioPlay" src="1.mp3" hidden="true" />';
                    if($('body').find('audio').length <= 0) {
                        $('body').append(strAudio);
                    }

                    var audio = $('#audioPlay');
                    audio.play();
                }
            }
        </script>
    </head>
    <body>
        <input type="button" value="点击提示音" onclick="playSound()" />
    </body>
</html>

 

转载于:https://www.cnblogs.com/minozMin/p/9861044.html

php技术微信