Changes introduced with IE 5+ and Navigator 6+ have made javascript
control of sound problematic. Different browsers and OS's do not
universally support javascript control of plugins (such as quicktime).
It is nearly impossible to develop compatible javascript routines.
For more information see Wilson's
page on javascript control of sound.
This page documents a work-around. There are predictable cross-platform
routines to embed sound in a web page so that it will play when a page
is loaded. This work-around uses javascript to open small inobtrusive
windows whose only purpose is to play sounds. Multiple sounds can
thus be activated from links and rollovers.
The bold part is the part that embeds a sound called "vivaldi2.mid".
You would need to change all references to that to whatever your sound
files name was. The classid is required by the object tag to identify
what plug in is referenced. This number and the codebase is specific
to quicktime. You would need to get that information for whatever
plug-in you were using. You would need one of these html pages for
each sound you wanted to play. Also you could set parameters such
as looping etc. The rest of the html is shown just to show where
the object code is inserted in the head section.
| html code for a page called vivaldi.html that plays embedded sound
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<OBJECT classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"
<PARAM name="src" value="vivaldi2.mid">
<EMBED width="180" height="160"
</OBJECT> </head>
|
| Function to open window and play indicated page (tarmu)
function loadWindow(tarmu) {
|
Code to activate a link to call function
<a href="javascript:loadWindow('vivaldi.html')">Click to hear Vivaldi
|
The routine has one variable arbitraily called tarmu. The code that calls it miust indicate what html page it wants loaded In this example the link calls for an html page called vivaldi.html. The function then substitutes the actual name for tarmu. The routine sets parameters for the window to make it as small as possible.and locate it outside the viewer's vision. These location parameters won't work in navigator. The routine then calls the javascript method blur() which puts the sound window below the screen window.
Instead of linking to an html page the link links to a javascript routine. The routine calls the loadWindow function and specifies a page to load (in this example vivaldi.html. The same routine could be used to call other pages. All that would need to be changed is the 'vivaldi.html' inside the parenthesis.
** Note: if you copy this html page, you
will also need to copy the sounds or substitute your own sounds and change
the code for the examples to work.
| Function to close the sound window
function closer() {
|
Code for link to stop music by closing window
<a href="javascript:closer()">Stop Vivaldi </a> |
roll
over me to start music - roll out to stop
| <a href="blank.html" onMouseover="loadWindow('vivaldi.html')" onMouseout="closer()">roll
over me to start music - roll out to stop
</a> |
| function loadWindow(bookgif) {
muWindow = window.open(bookgif, "muWin", "toolbar = no, scrollbars=no,top=3200,left=3000,location=no,width=2,height=2") muWindow.blur() } function closer() {
|
function loadWindow2(bookgif) { muWindow2 = window.open(bookgif, "muWin2", "toolbar = no, scrollbars=no,top=3200,left=3000,location=no,width=2,height=2") muWindow2.blur() } function closer2() {
|
| Click to hear Vivaldi
in window 1
Click to hear Bach in window 1 Stop whatever is playing in window 1 |
Click to hear Vivaldi
in window 2
Click to hear Bach in window 2 Stop whatever is playing in window 2 |
|
<a href="javascript:loadWindow('playsound1.html')">Click to hear Vivaldi in window 1</a> <br><a href="javascript:loadWindow('playsound2.html')">Click to hear Bach in window 1</a> <br><a href="javascript:closer()">Stop whatever is playing in
window 1</a
|
<a href="javascript:loadWindow2('playsound1.html')">Click
to hear Vivaldi
in window 2</a> <br><a href="javascript:loadWindow2('playsound2.html')">Click to hear Bach in window 2</a> <br><a href="javascript:closer2()">Stop whatever is playing in window 2</a> |