Link to home
Create AccountLog in
Avatar of Chi Is Current
Chi Is CurrentFlag for United States of America

asked on

Play wav sound upon link click

Hello ~

I'd like to play a .wav file on a web page when I click a link.  I found the following script on EE circa 1997, and am not getting it to run.  

Page: 1index.html
File to play: Bark1a.wav
Text link: BARK! - Work in Progress

The 'Bark1a.wav' file does reside in the same directory as the '1index.html' page.

I would appreciate your assistance.


function start()



<a href="JavaScript:start();">BARK! - Work in Progress</A>


Many Thanks, Jacob
Avatar of Richard Davis
Richard Davis
Flag of United States of America image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Most of the methods of playing/controlling sounds in Javascript involve using <embed> to embed a WAV file in the page. The problem is it requires that WMP be installed, and the user gets an "ActiveX Warning" on the page and has to accept for it to work.

Someone released a Flash based WAV file player. It's invisible, you put it on the page, and then use Javascript to send commands to Flash. Flash handles the playing of all the sound files. Looked pretty nifty to me.

download page:
Avatar of Chi Is Current


Thank you both for your ideas.

Adrian ~  Your solution appears easy to implement.

However, when I place the code on my page, it doesn't play the sound.

If you could have a look:

Adrian ~

I'm attempting option #4 on your example.

In the script, do I need to replace 'document' with my file name (1index.html)? :

function EvalSound(soundobj) {
  var thissound=document.getElementById(soundobj);

<embed src="Bark1.wav" autostart=false width=0 height=0 id="sound1"

The button form is written:

<input type="button" value="Play Sound" onClick="EvalSound('sound1')">

Adrian ~

OK ~  I had the name written incorrectly for my .wav file.

'Script works GREAT.  Fast!!!


Great!  Thank you!  I'm a big fan of elegant simplicity.

Best Regards, Jacob
Sorry for not responding back to your additional questions, but gad that it proved helpful from that page I sent you. :)

Take care