---
title: "chrome、firefox多浏览器兼容的解决方案"
author: "ajonjun"
date: "2013-12-20T23:27:38Z"
tags: []
categories: ["Web前端"]
slug: "chrome-firefox"
draft: false
lastmod: "2013-12-20T23:27:38Z"
id: 1993228
url: "https://hecks.iteye.com/blog/1993228"
---

今天又一朋友让帮忙解决他的页面中的背景音乐的问题，如果用bgsound只有ie支持，其它firefox,chrome浏览器都不支持。这里给出了具体的解决方法。  
打开一个空白控制面板粘贴下面代码,到网上搜索你要的歌曲,把地址复制过来保存   
&lt;embed src=音乐链接地址 width=200 height=50 type=audio/mpeg loop="true" autostart="true"&gt;   
width和height为播放器宽度和高度,可以灵活设置。   
autostart="true"为自动播放,autostart="false"为不自动播放.   
loop="true"为连续循环播放,loop="false"为不循环播放.   
loop可以等于一个整数,比如loop="3",就是音乐循环播放3次 

firefox如果不能播放，会提示安装quicktime ，经过测试(IE6+ firefox chrome测试通过)

以下是补充方法：推荐用第一种方法:

&lt;embed src="bgsound.mp3" height="45" width="250"&gt; 

其中src 后跟要插入的音乐文件的名称，height和width是播放框的高度和宽度。 

如果希望在网页打开后自动播放音乐，可使用如下代码： 

&lt;DIV align=center&gt;&lt;embed src="bgsound.mp3" height="45" width="250" autostart="true" &gt;&lt;/DIV&gt; 

如果希望播放框居中显示，可使用如下代码： 

&lt;DIV align=center&gt;&lt;embed src="bgsound.mp3" height="45" width="250"&gt;&lt;/DIV&gt; 

要让你的网页能够在Firefox浏览器中播放背景音乐，使用object标签。[]()   
以下是一段标准的、跨浏览器的代码示例：

&lt;object data="music/bgsound.mp3" type="application/x-mplayer2" width="0" height="0"&gt;   
&lt;param name="src" value="music/bgsound.mp3"&gt;   
&lt;param name="autostart" value="1"&gt;   
&lt;param name="playcount" value="infinite"&gt;   
&lt;/object&gt; 

来源：[Heck's Blog](http://www.hecks.tk/)  
地址：[http://www.hecks.tk/post/408/](http://www.hecks.tk/post/408/)  
转载时须以链接形式注明作者和原始出处及本声明，否则将追究法律责任，谢谢配合！