I have the following code on the page of my site - when a user clicks on an image, a sound is played:
<script language="javascript" type="text/javascript">
function playSound(soundfile) {
document.getElementById("dummy").innerHTML=
"<embed src=\""+soundfile+"\" hidden=\"true\" autostart=\"true\" loop=\"false\" />";
}
</script>
<span id="dummy"></span>
<div id="soundimage">
<a href="#" onclick="playSound('sound.mp3');"><img src="image.png" /></a>
</div>
Everything works fine, but the image is at the bottom of the page, and when the user clicks on the image, he is redirected back to the top of the page. Is there a way to make this work so that there is only a change in sound, not a visual one (if that makes sense!)?
When using the mouseover function, for example
<a onmouseover="playSound('sound.mp3');"><img src="image.png" /></a>
the user remains where he was on the page, but I would like them to be able to play sound by click, and not when rollover.
source
share