C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Javascript »

MouseOver sound using JavaScript


Posted Date: 03 Jul 2009    Resource Type: Code Snippets    Category: Javascript
Author: ManigandanMember Level: Gold    
Rating: 1 out of 5Points: 12



Hi,

This code snippets will give you additional impact for your programs.
If you mouse over the icon you can hear the sound.


<script LANGUAGE="JavaScript"><!--
// Preload and play audio files with event handler (MouseOver sound)


var aySound = new Array();

aySound[0] = "laser.wav";


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;iStr += "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>



Then You have to add the sound files in array for Preload actions:

aySound[0]="YourSoundFile.wav";
aySound[1]="AnotherSoundFile.wav";
aySound[2]="EvenAnotherOne.wav";
etc.,



Then you have to do the code with Event Handler,
MouseOver/MouseOut

<A HREF="YourPage.html" onMouseOver="playSound(0)" onMouseOut="stopSound(0)">Move mouse over to play sound</A>


In OnClick Sound:

<A HREF="javascript:playSound(0);">Click here to play sound</A>


If you are performing operation by clicking the Buttons means,

<INPUT TYPE="BUTTON" VALUE="Click me!" onClick="playSound(0)">




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Mouse Click Sound Event in JavaScript  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Changing Back Ground color of the Page
Previous Resource: Displaying CountDown While Redirecting the Page using JavaScript
Return to Discussion Resource Index
Post New Resource
Category: Javascript


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use