Background Sound

JavaScript FAQ | JavaScript Sound FAQ  

Question: How do I set a background sound on my Web page?

(1) Please don't! Many users find background sound on webpages very annoying. They will:

In some client configurations, there is no easy way to stop the background sound from within the browser (or, rather, the easiest way to stop the sound is to leave the page.) Therefore, please avoid background sound playback starting without any action of the user. Instead, use these techniques:

(2) That said, there are ways to play background sound on your pages. In most browsers, you can use the EMBED tag (which is now considered obsolete) to play a background sound. For example, if you want to play the file bkground.mid right after the browser loads the page, you can use the following tags:

<SPAN ID="soundBlock">
<EMBED ID="bkgroundID" SRC="bkground.mid"

To stop the background sound, you can use this function:

function stopBackgroundSound() {

If your target browser is Microsoft Internet Explorer (for example, in an intranet), then you can also use the Explorer-specific BGSOUND tag:

<BGSOUND ID="bkgroundID" LOOP=0 VOLUME="-600" 
Here, again, bkground.mid stands for the name of the sound file that you actually want to play.

Copyright © 1999-2011,