mouse over sounds

Having problems with DHTML Menu? There is usually somebody here who knows the answer.
Post Reply
ccater
Beginner
Beginner
Posts: 3
Joined: Mon Jun 11, 2007 2:52 pm

mouse over sounds

Post by ccater »

hi all,

I was wondering if it is possible to have a sound happen when you rollover a menu item, and if so, what would the code be?

Thanks :)
COL
User avatar
Ruth
 Team
 Team
Posts: 8763
Joined: Thu May 15, 2003 5:02 am
Location: Yucaipa, CA
Contact:

Re: mouse over sounds

Post by Ruth »

Yes, it is.

There are a lot of mouseover codes out there for sound. Most are browser specific. I found one that is cross browser, at least it works in Netscape7.1, 9, Opera 7.1, 7.54, Firebird .07, Firefox 1.0.2, 1.5, 2.0.0.3, IE 5.5, 6. I can't get it to work in Netscape6 or 4.79. That may be because of whatever audio is used with them. I think 6 wants me to get quicktime, even though I have it set to use windows media player, and 4.79 uses some kind of sound class and beatnik. I do not have mac so am unable to test for that OS.

So, to set up sound on mouseover you'd put this at the top of the menu data file

Code: Select all

function DHTMLSound(surl) {
  document.getElementById("dummyspan").innerHTML=
    "<embed src='"+surl+"' hidden=true autostart=true loop=false>";
}
Then in the aI string where you want the sound on mouseover you'd call it like this

Code: Select all

aI("text=Home;url=http://milonic.com/;onfunction=DHTMLSound('success.wav');");
Finally, you need to place a 'dummy' span on every page where you want it to work.

Code: Select all

<span id=dummyspan></span>
If no span is posted, the sound won't play and an error message will be given that document.getElement is null or not an object.

I do not know js functions but it would seem that for someone who does it would be possible to edit the sound function to add an if/else statement so no error message is generated if no span is on the page. Something where you tell it if the dummy span is there then play the sound, else no sound.

Ruth
Post Reply