Jquery web page auto playback sound

  • 2020-03-30 02:47:09
  • OfStack

 
<script type="text/javascript" src="jquery-1.7.2.min.js"></script> 
<script type="text/javascript"> 
$(function(){ 
//The following two sites are referenced here
//http://www.w3school.com.cn/html/html_audio.asp 
//http://www.zhanxin.info/development/2013-05-17-html5-audio.html 
if($.browser.msie && $.browser.version=='8.0'){ 
//It used to be <Bgsound SRC = "system. Wav" /> As a result, IE8 does not play sound, so it is replaced with embed
$('#newMessageDIV').html('<embed src="system.wav"/>'); 
}else{ 
//IE9+,Firefox,Chrome support Audio />
$('#newMessageDIV').html('<audio autoplay="autoplay"><source src="system.wav"' 
+ 'type="audio/wav"/><source src="system.mp3" type="audio/mpeg"/></audio>'); 
} 
}); 
</script> 

<div id="newMessageDIV" style="display:none"></div> 

Related articles: