Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can I add a sound (wav) to a link

Status
Not open for further replies.

jwset

Technical User
Aug 18, 2002
9
US
I have learned how to use MOUSEOVER to add text inplace of the link when someone goes over the button, I am wondering is there a way to add a sound (wav) to play also when someone moves their mouse over the button?

Here is the code I am trying to add sound too.
<a target=&quot;_blank&quot; href=&quot; here to view our Code of Conducts'; return true&quot;>
<img border=&quot;0&quot; src=&quot;buttons/codeofconduct.gif&quot; width=&quot;138&quot; height=&quot;32&quot;></a>

I am trying to figure out how to make a small wav sound play when they move there mouse over this button. Is there a way to do this?

If so can you please give me the code and where to place it so that when they go over this button it will play the selected sound.

Thank you bvery much for any help on this.

J.W.
 
This works
Code:
<html>
<head>
<script LANGUAGE=&quot;JavaScript&quot;><!--

var aySound = new Array();

aySound[0] = &quot;YourSound.wav&quot;;
aySound[1] = &quot;YourSound2.wav&quot;;//****[COLOR=red]Put your sound wav file here in the same directory as your page. YOU can add as many sound files as needed[/color]

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

function auPreload() {
if (!ver4) return;
if (NS) auEmb = new Layer(0,window);
else {
Str = &quot;<DIV ID='auEmb' STYLE='position:absolute;'></DIV>&quot;;
document.body.insertAdjacentHTML(&quot;BeforeEnd&quot;,Str);
}
var Str = '';
for (i=0;i<aySound.length;i++)
Str += &quot;<EMBED SRC='&quot;+aySound[i]+&quot;' AUTOSTART='FALSE' HIDDEN='TRUE'>&quot;
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(&quot;this.document.embeds[whSound].&quot; + (play? &quot;play()&quot;:&quot;stop()&quot;))
}
function playSound(whSound) { if (window.auCon) auCon.control(whSound,true); }
function stopSound(whSound) { if (window.auCon) auCon.control(whSound,false); }
//-->
</script>

</head>
<body>
<a href=&quot;HomePage.htm&quot; target=&quot;thebody&quot;onFocus=&quot;playSound(0)&quot; onBlur=&quot;stopSound(0)&quot;><br>
<a href=&quot;AnotherPage.htm&quot; target=&quot;thebody&quot;onFocus=&quot;playSound(1)&quot; onBlur=&quot;stopSound(1)&quot;>
</body>
</html>
 
oops sorry I forgot to add text for the link.. To see this in action got to; <a href=&quot;HomePage.htm&quot; target=&quot;thebody&quot;onFocus=&quot;playSound(0)&quot; onBlur=&quot;stopSound(0)&quot;>Sound1</a><br>
<a href=&quot;AnotherPage.htm&quot; target=&quot;thebody&quot;onFocus=&quot;playSound(1)&quot; onBlur=&quot;stopSound(1)&quot;>Sound2</a>
</body>
 
Thank you very much now I can give it a try.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top