Play sound

From , 4 Years ago, written in JavaScript, viewed 51 times.
URL https://pastebin.vip/view/18d80423
  1. function playSound() {
  2.         var borswer = window.navigator.userAgent.toLowerCase();
  3.         if (borswer.indexOf("ie") >= 0) {
  4.             //IE内核浏览器
  5.             var strEmbed = '<embed name="embedPlay" src="../../images/sound/alert.mp3" autostart="true" hidden="true" loop="false"></embed>';
  6.             if ($("body").find("embed").length <= 0)
  7.                 $("body").append(strEmbed);
  8.             var embed = document.embedPlay;
  9.  
  10.             //浏览器不支持 audion,则使用 embed 播放
  11.             embed.volume = 100;
  12.             embed.play();
  13.         } else {
  14.             //非IE内核浏览器
  15.             var strAudio = "<audio id='audioPlay' src='../../images/sound/alert.mp3' hidden='true'>";
  16.             if ($("body").find("audio").length <= 0)
  17.                 $("body").append(strAudio);
  18.             var audio = document.getElementById("audioPlay");
  19.  
  20.             //浏览器支持 audion
  21.             audio.play();
  22.         }
  23.     }

Reply to "Play sound"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website