spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column20


The BGSOUND Tag

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

Explorer's <BGSOUND> tag is the simplest way to embed background sound in your page. It may be placed either within the HEAD or the BODY portion of the page. Remember to turn ON your browser's "Play sounds" option, under "Edit"/"Internet-Options"/"Advanced". Here is an html code that will the Aladdin soundtrack ten times, every time you load it:

<HTML>
<HEAD>
<TITLE> testing  </TITLE>
</HEAD>
<BODY>
<BGSOUND SRC="aladdin.mid" LOOP=10>
</BODY>
</HTML>

Similarly, the following HTML code will the X-files soundtrack five times:

<HTML>
<HEAD>
<TITLE> testing  </TITLE>
</HEAD>
<BODY>
<BGSOUND SRC="xfiles.mid" LOOP=5>
</BODY>
</HTML>

Microsoft documents specify more parameters for the <BGSOUND> tag than are currently supported. The following table lists the supported ones:

ParameterDescription
ID="idvalue"An identifier to be used for references in associated style sheet, hypertext links, and JavaScript code. Must begin with a letter and may include underscores. ID should be unique within the scope of the document. If duplicated, the collection of identical-ID elements may be referenced by their ordinal numbers.
LOOP="n"Specifies how many times the sound will loop.
SRC="url"Specifies the URL of the sound file. As shown above, sound files can be in any recognizable format (for example: "midi, wav, au")
VOLUME="n"Determines the loudness of the background sound. Values may range from -10,000 (weakest) to 0 (loudest). Not supported by the MAC.

The following parameters are not supported:

ParameterDescription
BALANCE="n"Determines the division of sound power between the left and right speakers. Valid values are between -10,000 and +10,000, with 0 being perfect balance between the two.
CLASS="classname"The class of the tag to be used for assigning sub-class style sheet.
TITLE="text"Specifies text to accompany the sound.
LANG="language"Specifies the language to be used, in ISO standard abbreviation format.

You can reference the <BGSOUND> element in a JavaScript script. The sound-related properties are balance, loop, src, and volume. The src and loop properties are supported on both the PC and the Mac computers. The volume property is supported only on PC.

To demonstrate the usage of JavaScript for controlling the background sound of a page, here is that will switch between the Aladding and X-files soundtracks every 30 seconds:

<HTML>
<HEAD>
<TITLE> testing  </TITLE>
</HEAD>
<BODY>
<BGSOUND SRC="aladdin.mid" ID="changetrack">
<SCRIPT>
<!--
setInterval("switchMelody()",30000);

function switchMelody(){
  if (document.all.changetrack.src == "aladdin.mid") 
    document.all.changetrack.src = "xfiles.mid"
  else document.all.changetrack.src = "aladdin.mid";
}
//-->
</SCRIPT>
</BODY>
</HTML>

This code does not have any effect on the Mac computer. On Mac, <BGSOUND>'s properties cannot be changed by a JavaScript script in the middle of a soundtrack.

http://www.internet.com

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint


Created: May 31, 1998
Revised: May 31, 1998

URL: http://www.webreference.com/js/column20/bgsound.html