Example 1. Here's the simplest cross-browser
script for playing a sound file:
Click here to test the
code of Example 1. Most modern browsers will close the current page
nor would they particularly like additional sound control windows!
To start playing:
To stop playing:
stands for the name of the sound file that you actually want to play;
is a "do-nothing" sound file
it does not play any sound at all, but can be used to stop the playback of other sound files.
In Netscape Navigator, you had to use the LiveAudio plugin and put an
tag on your page. For example, to play the file
and hide the LiveAudio window, you could use the following
In Netscape Navigator 4.x, the
would stop the playback of the current audio file. Most modern brosers support the
tag too; however, the tag is no longer scriptable in most configurations (e.g.
no longer works) and the tag itself is now considered obsolete
, use the
tag (see below).
In Firefox, Safari, and Google Chrome the audio playback functionality relies on plugins such as Apple QuickTime. With the audio plugin(s) installed, you will need an
tag for the browser to activate the plugin. Here is an example of an
The Opera browser now supports all of the above tags:
, and even
won't work here).
The source code of Example 2 is shown below. If the user has Internet Explorer, the code relies on the
technique described above. In browsers other than Internet Explorer, the code expects that the current browser window has an
that actually start and stop the playback.
The helper page
from another domain in our
directly, and then use
to further change the
sniffs the browser and renders HTML for the playback of
(which can be a relative URL like