Want to add a short sound effect to your page for certain actions, such as when the user moves the mouse over a link? This is a simple yet versatile script that lets you do just like! Relying on IE's BGSOUND attribute (and hence IE5+ only), the script can easily add a sound effect to a single item (ie: 1 link), or thanks to a helper function, all items of the specified element (ie: all <a> tags). This makes it very easy to add a sound effect to an entire menu's links, for example. <bgsound src="#" id="soundeffect" loop=1 autostart="true" /> <script type="text/javascript"> 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>
Read More..2008-03-03
Javascript sound effect
Posted by
Ribhararnus Pracutian
at
6:53:00 PM
0
comments
Links to this post
Labels: javascript tutorial
2008-03-01
This function is about : Certain situations call for the refreshing of the webpage every few seconds/ minutes (such as a webcam page). Use Brett's script to carry out this task in a graceful, "visual" manner. Step : Copy Paste into your HTML code <script language="JavaScript"> //configure refresh interval (in seconds) var countDownInterval=60; //configure width of displayed text, in px (applicable only in NS4) var c_reloadwidth=200 </script> <ilayer id="c_reload" width=&{c_reloadwidth}; ><layer id="c_reload2" width=&{c_reloadwidth}; left=0 top=0></layer></ilayer> <script> var countDownTime=countDownInterval+1; function countDown(){ countDownTime--; if (countDownTime <=0){ countDownTime=countDownInterval; clearTimeout(counter) window.location.reload() return } if (document.all) //if IE 4+ document.all.countDownText.innerText = countDownTime+" "; else if (document.getElementById) //else if NS6+ document.getElementById("countDownText").innerHTML=countDownTime+" " else if (document.layers){ //CHANGE TEXT BELOW TO YOUR OWN document.c_reload.document.c_reload2.document.write('Next <a href="javascript:window.location.reload()">refresh</a> in <b id="countDownText">'+countDownTime+' </b> seconds') document.c_reload.document.c_reload2.document.close() } counter=setTimeout("countDown()", 1000); } function startit(){ if (document.all||document.getElementById) //CHANGE TEXT BELOW TO YOUR OWN document.write('Next <a href="javascript:window.location.reload()">refresh</a> in <b id="countDownText">'+countDownTime+' </b> seconds') countDown() } if (document.all||document.getElementById) startit() else window.onload=startit </script>
Read More..
Posted by
Ribhararnus Pracutian
at
1:30:00 AM
0
comments
Links to this post

