Home Other JavaScript Sound Effect Developer's View
<html>
<head>
<bgsound src="#" id="soundeffect"
loop=1 autostart="true" />
<script type="text/javascript">
/***********************************************
* JavaScript Sound effect- (c) Dynamic Drive DHTML code library
(www.dynamicdrive.com)
* Visit http://www.dynamicDrive.com for hundreds of DHTML scripts
* Please keep this notice intact
***********************************************/
var soundfile="sidebar.wav" //path to sound file, or pass in filename directly
into playsound()
function playsound(soundfile){
if (document.all && document.getElementById){
document.getElementById("soundeffect").src="" //reset first in case of problems
document.getElementById("soundeffect").src=soundfile
}
}
function bindsound(tag, soundfile, masterElement){
if (!window.event) return
var source=event.srcElement
while (source!=masterElement && source.tagName!="HTML"){
if (source.tagName==tag.toUpperCase()){
playsound(soundfile)
break
}
source=source.parentElement
}
}
</script>
</head>
<body>
<a href="#"
onMouseover="playsound(soundfile)">Example 1</a>
<a href="#" onMouseover="playsound('different.wav')">Example 2</a>
<div id="coolmenu"
onMouseover="bindsound('A', soundfile, this)">
<a href="http://www.cssdrive.com">CSS Drive</a>
<a href="http://www.dynamicdrive.com"">Dynamic Drive</a>
<a href="http://www.javascriptkit.com">JavaScript Kit</a>
<a href="http://www.wired.com">Wired news</a>
<a href="http://www.codingforums.com">Coding Forums</a>
</div>
</body>
</html>