zoukankan      html  css  js  c++  java
  • JS播放声音

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>JS播放声音</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js"></script>
    </head>
    <body>
    <script language="javascript">
    playVoice();
    function playVoice()
        {
          var borswer = window.navigator.userAgent.toLowerCase();
          if(borswer.indexOf( "ie" ) >= 0)
          {
            //IE内核浏览器
            var strEmbed = '<embed name="embedPlay" src="dingdong.wav" autostart="true" hidden="true" loop="false"></embed>';
            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='dingdong.wav' hidden='true'>";
            if($("body").find("audio").length <= 0){
             $("body").append(strAudio);
            }
            var audio = document.getElementById("audioPlay");
     
            //浏览器支持 audio
            audio.play();
          }
        }
    </script>
    </body>
    </html>
    

      dingdong.wav为声音文件,放在HTML文件相同目录下

    转自:https://blog.csdn.net/quincylk/article/details/77853880

  • 相关阅读:
    go test 下篇
    go test 上篇
    利用Docker Compose快速搭建本地测试环境
    phinx:php数据库迁移
    tp5 r3 一个简单的SQL语句调试实例
    TP开发小技巧
    优酷真实视频地址解析——2014年10月7日
    霍夫变换
    Google Earth影像数据破解之旅
    线程理论:(四)锁优化
  • 原文地址:https://www.cnblogs.com/yangyangblog/p/10552666.html
Copyright © 2011-2022 走看看