Click to See Complete Forum and Search --> : [RESOLVED] sound in webpage


iamlost
11-08-2008, 03:56 PM
I run a family website and have a sound question. I would like the visitor to be able to move their mouse over a picture and a sound is made. Any help?

savvykms
11-08-2008, 07:41 PM
This is not HTML, it is javascript. But i know how to do it :)

This is an old example I used somewhere on these forums:

<html>
<head>
<title>Javascript Sounds - by Savvy</title>
<script language="javascript" type="text/javascript">
<!--
function playsound(sound) { document.getElementById("mysound").src = sound; }
function stopsound() { document.getElementById("mysound").src = ""; }
-->
</script>
</head>
<body>
<bgsound id="mysound" loop="infinite">
<p onmouseover="playsound('mywave.wav')" onmouseout="stopsound()">mouseoverme</p>
</body>
</html>


Place this in the <head> section of your web page:

<script language="javascript" type="text/javascript">
<!--
function playsound(sound) { document.getElementById("mysound").src = sound; }
function stopsound() { document.getElementById("mysound").src = ""; }
-->
</script>

Use this HTML code:

<bgsound id="mysound" loop="infinite">
<img src="image/file.jpg" alt="Some Image Caption" onmouseover="playsound('mywave.wav')" onmouseout="stopsound()">


If you want to do this for an image and some text, get both to work by adding these as HTML attributes:

onmouseover="playsound('mywave.wav')" onmouseout="stopsound()"


In all sections from before, replace file paths (such as 'mywave.wav' or "image/file.jpg") with your paths. bgsound is an old element, and may not work in some broswers.

iamlost
11-08-2008, 08:02 PM
Thanks for your help.

savvykms
11-08-2008, 08:12 PM
No problem.
Don't forget to change your thread to resolved. :)