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.