Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Play sound onclick

Status
Not open for further replies.

TechDude

Programmer
Jul 20, 2000
62
US
I need to create an object for a .wav file which I can trigger to play onclick I'm not really sure how to go about that, any ideas? <br><br>thanks<br><br>&nbsp; <p>Chris Sorel<br><a href=mailto:chris@exnihilo.com>chris@exnihilo.com</a><br><a href= If you continue to do what you have always done,<br>
you will continue to get what you have always gotten.
 
It's quite simple. You just have to create a little fonction (let's call iot 'playSound()') that you will call with anykind of action (onClick, onLoad, onUnload, etc.).<br><br>Here is a little piece of code that you can use :<br><br>&lt;script language=&quot;JavaScript&quot;&gt;<br>&lt;!--<br><br>function playSound()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;location.href=&quot;Mysound.wav&quot;;<br>}<br><br>//--&gt;<br>&lt;/script&gt;<br><br>&lt;img src=&quot;Myimage.gif&quot; onClick=&quot;playSound()&quot;&gt;<br>
 
Does that work in NN4+ viliche? Very elegant. I must try it.

You can also EMBED the sound with autostart off and call the sound via it's ID usinf the play() method in IE5.5.
 
I like this, but I would like for the user to be able to turn the sound off by clicking again. How do I amend this script to do that? Thanks! Calista :-X
Jedi Knight,
Champion of the Force
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top