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

Q784 How can I play a sound when an image is clicked?

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

Try:

<script language="JavaScript"><!--
var can_play = false;

var mimetype = 'audio/midi';

if (navigator.mimeTypes) {
    if (navigator.mimeTypes[mimetype] != null) {
        if (navigator.mimeTypes[mimetype].enabledPlugin != null) {
            can_play = true;
            document.write('<EMBED SRC="sound.mid" HIDDEN=TRUE LOOP=FALSE AUTOSTART=FALSE>');
        }
    }
}

function playSound() {
    if (document.embeds && can_play) {
        if (navigator.appName == 'Netscape')
            document.embeds[0].play();
        else
            document.embeds[0].run();
    }
}
//--></script>

<a href="#" onClick="playSound()"><img src="image.gif" width="100" height="100" border="0"></a>

©2018 Martin Webb