You are here: irt.org | FAQ | JavaScript | Sound | Q1223 [ previous next ]
Try:
<script language="JavaScript"><!--
if (navigator.mimeTypes) {
if (navigator.mimeTypes[mimetype] != null) {
if (navigator.mimeTypes[mimetype].enabledPlugin != null) {
can_play = true;
document.write('<embed name="sound1" src="sound1.mid" hidden=true loop=false autostart=false>');
document.write('<embed name="sound2" src="sound2.mid" hidden=true loop=false autostart=false>');
document.write('<embed name="sound3" src="sound3.mid" hidden=true loop=false autostart=false>');
document.write('<embed name="sound4" src="sound4.mid" hidden=true loop=false autostart=false>');
}
}
}
function playSound(idx) {
if (document.embeds && can_play) {
if (navigator.appName == 'Netscape')
document.embeds["sound"+idx].play();
else
document.embeds[soundName].run();
}
if (document.images)
document.images["img"+idx].src = "img"+idx+"on.gif"
}
function stopSound(idx) {
if (document.embeds && can_play)
document.embeds["sound"+idx].stop();
if (document.images)
document.images["img"+idx].src = "img"+idx+"off.gif"
}
//--><script>
<a href="#" onMouseover="playSound(1)" onMouseOut="stopSound(1)"><img name="img1" src="image.gif" width="100" height="100" border="0"></a>
<a href="#" onMouseover="playSound(2)" onMouseOut="stopSound(2)"><img name="img2" src="image.gif" width="100" height="100" border="0"></a>B De Roes suggests the following works on Internet Explorer 5.5:
<embed name="sound1" src="sound1.mid" hidden=true loop=false autostart=false>
<embed name="sound2" src="sound2.mid" hidden=true loop=false autostart=false>
<embed name="sound3" src="sound3.mid" hidden=true loop=false autostart=false>
<embed name="sound4" src="sound4.mid" hidden=true loop=false autostart=false>
<script language="JavaScript"><!--
var can_play = true; var mimetype = 'audio/midi';
function playSound(idx) {
if (document.embeds && can_play) {
document.embeds["sound"+idx].play();
}
if (document.images)
document.images["img"+idx].src = "img"+idx+"on.gif"
}
function stopSound(idx) {
if (document.embeds && can_play)
document.embeds["sound"+idx].stop();
if (document.images)
document.images["img"+idx].src = "img"+idx+"off.gif"
}
//--><script>
<a href="#" onMouseover="playSound(1)" onMouseOut="stopSound(1)"><img name="img1" src="image.gif" width="100" height="100" border="0"></a>
<a href="#" onMouseover="playSound(2)" onMouseOut="stopSound(2)"><img name="img2" src="image.gif" width="100" height="100" border="0"></a>