/    Sign up×
Community /Pin to ProfileBookmark

Audio on Mouse over Image

Hi, I am in serious need to have my webpage play a sound when I put my mouse over an image/link on my site. I have found some code that plays a sound when I mouse over a (<a href=) type link. But I want it to play a sound when I mouseover a .gif image in my page. I’m sure you would only have to change a small part of the code, although I know a little bit about Java & HTML, I couldn’t manipulate the code properly. If someone could help me I would be immensly greatful ?

Here is the code complete with instructions..

[CODE]Sounds when mousing-over a link

What if mousing-over a link on your site produced a sound?

Insert this small JavaScript program in the header of your page:

<script LANGUAGE=”JavaScript”>
<!–
var aySound = new Array();
aySound[1] = “http://nastybeatz.co.uk/Audio/Jungle_Skin_Head.mp3″;

document.write(‘<BGSOUND id=”auIEContainer”>’)
IE = (navigator.appVersion.indexOf(“MSIE”)!=-1 && document.all)? 1:0;
NS = (navigator.appName==”Netscape” && navigator.plugins[“LiveAudio”])? 1:0;
ver4 = IE||NS? 1:0;
onload=auPreload;

function auPreload() {
if (!ver4) return;
if (NS) auEmb = new Layer(0,window);
else {
Str = “<DIV ID=’auEmb’ STYLE=’position:absolute;’></DIV>”;
document.body.insertAdjacentHTML(“BeforeEnd”,Str);
}
var Str = ”;
for (i=0;i<aySound.length;i++)
Str += “<EMBED SRC='”+aySound[i]+”‘ AUTOSTART=’FALSE’ HIDDEN=’TRUE’>”
if (IE) auEmb.innerHTML = Str;
else {
auEmb.document.open();
auEmb.document.write(Str);
auEmb.document.close();
}
auCon = IE? document.all.auIEContainer:auEmb;
auCon.control = auCtrl;
}
function auCtrl(whSound,play) {
if (IE) this.src = play? aySound[whSound]:”;
else eval(“this.document.embeds[whSound].” + (play? “play()”:”stop()”))
}
function playSound(whSound) { if (window.auCon) auCon.control(whSound,true); }
function stopSound(whSound) { if (window.auCon) auCon.control(whSound,false); }
//–>
</script>

All sounds used on the page are defined in the aySound table. If you want to use more sounds, add a line of this

type:

aySound[0]=”my_sound.wav”;

Replace 0 by the number of the sound in the table and my_sound.wav by the sound file that you want to integrate

(including the full filepath if necessary).

Next, define each of your links as follows:

<A HREF=”YourPage.html” onMouseOver=”playSound(0)” onMouseOut=”stopSound(0)”>Your link here!</A>

Replace 0 by the number of the sound that you[/CODE]

Many thanks in advance..

Peace.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@mik74100May 04.2010 — Hi,

this script is beautiful. It works fine with Internet Explorer 8. But it does not with Firefox 3.6.3. I don't get any message from Firefox concerning missing plugins or similar.

I would be most grateful for an answer.

Mik
×

Success!

Help @DrNastE spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...