Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-30-2005, 04:11 PM   PM User | #1
SilentDrive
New Coder

 
Join Date: Dec 2004
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
SilentDrive is an unknown quantity at this point
Play a sound file with onClick()

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.
SilentDrive is offline   Reply With Quote
Old 07-01-2005, 01:12 AM   PM User | #2
WMJB
New Coder

 
Join Date: Mar 2005
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
WMJB will become famous soon enough
Include this tag in your html:

Code:
<BGSOUND SRC="#" ID="sound1" autostart="true">
then include this function:

Code:
function playAlert()
{
	document.getElementById('sound1').src="error.wav";
}
This was the easiest way I found to do it...
__________________
"It doesn't matter if I'm optomistic or not, nothing ever works out for me."
WMJB is offline   Reply With Quote
Old 07-01-2005, 01:22 AM   PM User | #3
_Aerospace_Eng_
Supreme Master coder!


 
_Aerospace_Eng_'s Avatar
 
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,293
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light
bgsound is IE only try this
Code:
<!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>
_Aerospace_Eng_ is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:31 PM.


Advertisement
Log in to turn off these ads.