Log in

View Full Version : a cross browser sound function for IE and FX



madhatterz
05-10-2006, 11:30 PM
hey I have a a nice little script for ya...

I couldnt get sounds on buttons in both IE and FX

I spent 4 hours reading and writing to make it work .. have little knowledge with coding...

it consists of a java script that I found in a forum discussion on the subject..

Put this between the <heads>

</script>

<script>
function EvalSound(soundobj) {
var thissound= document[soundobj];
thissound.Play();
}
</script>



first part is a embedded sound file, a little modified to work in firefox
=======================================================
this must be changed to the appropriate mediatype ---> type="audio/wav" for example type="application/asx" or other ....
=======================================================

------------------body part--------------------------------------------
<embed src="yuorsoundfile.wav" type="audio/wav" autostart="FALSE" loop="false"
width="0" height="0" name="sound1" enablejavascript="true">



then comes the button part :
<a href="page.html" target="" onmouseover="EvalSound('sound1')">
--------------------------------------------------------------------------

you may add or replace the onmousover with onclick or other function and it can easily be adapted to other applications
notice that the "Evalsound" sends also the id to which embedded file.. so u may have several embedded function working through the one javascript

I havent tested it with netscape or opera ... but it works like a dream in IE and FX :)
and in a menu u just use the same code over again.. and u control the audio though the embedded code...so u dont have to rewrite the entire menu to if u change sound or somethnig...

Peace out...

madhatterz
05-10-2006, 11:45 PM
That will only work if the FF user has installed the Quicktime plugin installed and configured to play wav files.

And here's a slightly simpler way:
embed tag:
<embed src="youraudiofile.wav" type="audio/wav" autostart="FALSE" loop="false"
width="0" height="0" id="sound1" enablejavascript="true">

trigger:
onmouseover="document.getElementById('sound1').play();"

No other script needed. Again, this will specifically only work for Quicktime.

djr33
05-11-2006, 12:07 AM
http://www.phon.ucl.ac.uk/home/mark/audio/play.htm

Twey
05-11-2006, 06:20 AM
Badly written; even the author tagged it as "old."

djr33
05-11-2006, 07:19 PM
The link? Still lots of useful info. Got a replacement link?

Twey
05-11-2006, 07:25 PM
This has been discussed a few times on this very forum. Search.

djr33
05-11-2006, 11:27 PM
...and I found that :)
(Last time... stored it, just posted it this time.)

but... yeah... I remember a couple conversations worth noting.

check them out, madhatterz.