faqts : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

6 of 8 people (75%) answered Yes
Recently 6 of 8 people (75%) answered Yes

Entry

What java script could be added to enable mouse-over-sound-effect in a webpage in mozilla?

Apr 7th, 2008 23:13
ha mo, Colin Fraser, veshno bhat,


As I understand it, Mozilla is fully javascript compliant, so the same
script rules should apply. I used this script which I think came from
IRT.org, it worked for me then in Netscape, but from memory IE flubbed
it. This should still work but it may require a bit of tweaking.  
try something like:
<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>');
        }
    }
}
if (document.all) {
    can_play = true;
    document.write('<embed src="metallica.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();
    }
}
function stopSound() {
    if (document.embeds && can_play)
        document.embeds[0].stop();
}
//--></script>
<a href="#" onMouseover="playSound()" onMouseOut="stopSound()"><img
src="metallica.gif" width="100" height="100" border="0"></a>
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com