// shall I write some keywords here to boost search engine ranking?

Tuesday, February 12, 2008

Background Music for Firefox

To play a background sound in IE is simple, just 1 line of html below will do:

<bgsound src="mysong.wav" autostart="true" loop="-1"/>

Unfortunately, this doesn't work in Firefox. For Firefox, normally embed tag is use:

<embed src="mysong.wav" autostart="true" loop="true"/>

This will work if the user have QuickTime player installed. The drawback of this method is user can see the player in your page.

Here is the little trick, just add hidden="true", and the player will be hidden.

<embed src="mysong.wav" autostart="true" loop="true" hidden="true"/>

Now you just need to detect user-agent, and determine to use <bgsound> or <embed> to play your background sound.