...

View Full Version : Play a sound file with onClick()



SilentDrive
06-30-2005, 05:11 PM
Okay I have been looking all over the net for a script to play a sound with the image/button is clicked... I can't get any to work for some reason. Does anyone have a working script I could use. It would be highly appreciated.

WMJB
07-01-2005, 02:12 AM
Include this tag in your html:


<BGSOUND SRC="#" ID="sound1" autostart="true">

then include this function:


function playAlert()
{
document.getElementById('sound1').src="error.wav";
}

This was the easiest way I found to do it...

_Aerospace_Eng_
07-01-2005, 02:22 AM
bgsound is IE only try this

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript"><!--
function play(what){
document.getElementById('music1').innerHTML="<embed type='application/x-mplayer2' id='music2' pluginspage='http://www.microsoft.com/Windows/MediaPlayer/' src='"+what+"' name='MediaPlayer1' width='1' height='1' controltype='2' showcontrols='1' showstatusbar='1' AutoStart='true' loop='false'></embed>";
}
function stopsong(){
document.getElementById('music1').innerHTML="";
}
//-->
</script>
</head>
<body>
<a href="http://urltosonghere.mp3" onclick="play(this.href);return false">Play Clip</a>
<br>
<a href="#" onclick="stopsong();return false">Stop Clip</a>
<br><br>
<span id="music1"></span>
</div>
</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum