Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

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

You are here: irt.org | FAQ | JavaScript | Sound | Q390 [ previous next ]

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?'

©2018 Martin Webb