Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q390 How can you make a .wav play when you click on an image?

irt.org | Knowledge Base | JavaScript | Sound | Q390 [ previous next ]

Q390 How can you make a .wav play when you click on an image?

You should use the <EMBED> tag.

The following will play the midi or wav file as soon as its loaded on a Java enabled browser:

<html>
<body>
<embed src="sound.wav" hidden=true>
</body>
</html>

The following allows you control when it plays:

<html>
<body>

<script language="JavaScript"><!--
function playSound() { document.firstSound.play(); }
function pauseSound() { document.firstSound.pause(); }
function stopSound() { document.firstSound.stop(); }
//--></script>

<a href="javascript:playSound()"><img src="play.gif" width="100" hight="100"></a><br>
<a href="javascript:pauseSound()"><img src="pause.gif" width="100" hight="100"></a><br>
<a href="javascript:stopSound()"><img src="stop.gif" width="100" hight="100"></a><br>

<embed src="sound.wav" hidden=true autostart=false loop=false name="firstSound" mastersound>

</body>
</html>

You can replace sound.wav with sound.mid.

Feedback on 'Q390 How can you make a .wav play when you click on an image?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 6th July 2009. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2009 irt.org, All Rights Reserved.