兼容各种浏览器的背景音乐循环播放的JS代码

前端APP 投稿 11700 0 评论

兼容各种浏览器的背景音乐循环播放的JS代码

兼容各种浏览器的背景音乐循环播放的JS代码,具体代码如下:


var bgSoundFile = "https://www.feishuai.vip/style/bgsound.mp3";

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

编程笔记 » 兼容各种浏览器的背景音乐循环播放的JS代码

赞同 (48) or 分享 (0)
游客 发表我的评论   换个身份
取消评论

表情
(0)个小伙伴在吐槽