js背景音乐循环播放代码(多浏览器支持)

发布时间:2020-12-09编辑:脚本学堂
本文介绍了js背景音乐的循环播放代码,支持多浏览器,很实用的js背景音乐代码,有需要的朋友参考下。

例子,js背景音乐代码。
 

复制代码 代码示例:

//循环播放背景音乐
var mp3snd = "./xxx.mp3";
var bkcolor = "000000";

if ( navigator.userAgent.toLowerCase().indexOf( "msie" ) != -1 ) {
document.write('<bgsound src="'+mp3snd+'" loop="-1">');
}
else if ( navigator.userAgent.toLowerCase().indexOf( "firefox" ) != -1 ) {
  document.write('<object data="'+mp3snd+'" type="application/x-mplayer2" width="0" height="0">');
  document.write('<param name="filename" value="'+mp3snd+'">');
  document.write('<param name="autostart" value="1">');
  document.write('<param name="playcount" value="infinite">');
  document.write('</object>');
} // www.jb200.com
else {
  document.write('<audio src="'+mp3snd+'" autoplay="autoplay" loop="loop">');
  document.write('<object data="'+mp3snd+'" type="application/x-mplayer2" width="0" height="0">');
  document.write('<param name="filename" value="'+mp3snd+'">');
  document.write('<param name="autostart" value="1">');
  document.write('<embed height="2" width="2" src="'+mp3snd+'" pluginspage="http://www.apple.com/quicktime/download/" type="video/quicktime" controller="false" controls="false" autoplay="true" autostart="true" loop="true" bgcolor="#'+bkcolor+'"><br>');
  document.write('</embed></object>');
  document.write('</audio>');
}