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

Q1223 How do I add sound as well as image swapping to my mouseovers?

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

Q1223 How do I add sound as well as image swapping to my mouseovers?

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>

Feedback on 'Q1223 How do I add sound as well as image swapping to my mouseovers?'


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.