You are here: Reference > JavaScript > client-side > HTML DOM > properties > src (bgsound)

src property (bgsound)

Browser support:
Sets or retrieves the URL of a sound file to be played.
The bgsound element supports only .mid and .wav media file types.

Syntax:

object.src;
You can find the related objects in the Supported by objects section below.
This property is read/write.
HTML page for this property: src

Possible values:

String that sets or retrieves the URL of the sound file. It can be an absolute or relative path as well. Relative paths are relative to the base URL. The base URL is the location of the current document, but it can be overridden by the base tag.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the src attribute:
<bgsound src="budgie.wav" loop="-1" balance="10000">
Did you find this example helpful? yes no

Example HTML code 2:

This example illustrates the use of the src property:
<head>
    <script type="text/javascript">
        function GetSrc () {
            var sound = document.getElementById ("mySound");

            if ('src' in sound) {
                alert (sound.src);
            } else {
                alert ("Your browser doesn't support this example!");
            }
        }
    </script>
</head>
<body>
    <bgsound id="mySound" src="budgie.wav" loop="-1" balance="10000">

    <button onclick="GetSrc ();">Get sound location!</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

External links:

User Contributed Comments

Post Content

Post Content