spacer

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

home / experts / javascript / column20


The BGSOUND Tag

Developer News
OpenOffice 3.2 Lands Amid Critical Changes
Red Hat, IBM Firmly in KVM Virtualization Camp
Red Hat Talks Up Open Source Cloud Plans

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


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

webref The latest from WebReference.com Browse >
Search Engine Optimization: Selecting and Embedding Keywords · Are Google's Language Translation Web Services Ready for Prime Time? · Installing and Using Meeplace, the Business Review CMS
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
IBM DB2 10 for z/OS: Justifying the Upgrade · Living La Vida Colo: Choosing the Right Colocation Facility · FTC Concerns over Social Media Privacy Linger


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

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