View Full Version : Click on link to play background music!
GrimzWizard
12-21-2002, 08:47 PM
I have pictures in my website, and I want that when you click on it, the music plays on the background.
But it's like a selection... here's what I want to do:
Picture 1: on click, play 1stmusic.mid in background
Picture 2: on click, play 2ndmusic.mid in background
Picture 3: on click, play 3rdmusic.mid in background
Picture STOP: on click, stop everything you hear on background
ACJavascript
12-21-2002, 10:17 PM
how bout this,, might not work didn't test it hehe :D
_____-
<script language="javascript">
function sound(s){
document.bgSound.src=s
}
</script>
Call it like this
<img src="yourimage.gif" onclick="sound('Sound1.mid')">
_________
hope it works LOL :D
GrimzWizard
12-21-2002, 10:29 PM
Nope... :(
And can it be compatible with IE and Netscape?
ACJavascript
12-21-2002, 10:36 PM
Well i only know how to do it in IE,, any body else now Netscape?
any ways heres the code for IE,
<html>
<head>
<title>LSDJf</title>
<script language="javascript">
function play(s){
document.all.tags('bgsound')[0].src=s
}
</script>
</head>
<body>
<BGSOUND src="">
<img src="sdf.gif" onClick="play('OhYea3.mid')">
GrimzWizard
12-21-2002, 10:51 PM
COOL IT'S WORKING! I'm using Netscape Composer. Thank you very much!
Now from that code, how to stop the music when we re-click on the link?
TAG #1
<script language="javascript">
function play(s){document.all.tags('bgsound')[0].src=s}
</script>
TAG #2
<BGSOUND src="">
PICTURE LINK
javascript:;
onClick="play('1.mp3'); return false;"
ACJavascript
12-23-2002, 04:12 PM
To stop it just put in the onClick function - play('')
it will send a blank src to the bgsound tag. And play nothing wich means silence hehehe :D,, the only way i can think of to stop if after clicking it again,, it to use .innerHTML in IE. wich means no netscape :(
GrimzWizard
12-23-2002, 05:54 PM
Now waiting if anyone know Netscape with detection code...
kwhubby
12-24-2002, 10:30 AM
you can also use embeded objects and with them you can use the start() and play() predifined functions to make them go or stop.
zoobie
12-24-2002, 05:15 PM
It works in NS? :eek: I don't really see how it could...Try using embed (cross-browser since IE5) rather than bgsound and see what happens. Make a stop(); function same as play for more control. I don't think innerHTML can work in this instance. :D
dhtmlx
12-24-2002, 07:41 PM
This is what I used on an old site....I think it only works on IE.
Add this in the Body of the HTML
<bgsound src="" id=music loop="infinite" autostart="true">
then add this where the link is:
<a href="#" onclick="document.all.music.src='musicurl'; return false;">MUSIC On</a>
You have to make some sort of Function that detects which click it is but i dont know how.
I havent tested it but I hope it works
^KoalaBear^
12-26-2002, 01:43 AM
Originally posted by zoobie
Try using embed (cross-browser since IE5) rather than bgsound and see what happens.
Well here's my test setup from using acjavascript's suggested code... would you like to suggest what I add to this to get the same (or duplicate sound.gifs and strings) to play in N/S too?
Here is my TEST SITE (http://home.graffiti.net/aussiesites/play-midis-wavs/test.html)
Here is the test code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Mozilla/4.8 [en] (Win98; U) [Netscape]">
<title>Play a Midi or Wav</title>
<script language="javascript">
function play(s){
document.all.tags('bgsound')[0].src=s
}
</script>
</head>
<body text="#FF0000" bgcolor="#000000" link="#0000EE" vlink="#551A8B" alink="#FF0000">
<blockquote><b><font face="Arial,Helvetica"><font size=+1><font color="#FF0000">Play
</font><font color="#3366FF">wavs
</font><font color="#FF0000">and</font><font color="#3366FF">
midis</font><font color="#FF0000"> by ckicking on the associated sound.gif....
</font><font color="#FFFFFF">IE Only</font></font></font></b>
<br>
<br>
<br><b><font face="Arial,Helvetica"><font color="#FFCC00"><font size=-1></font></font></font></b>
<p><BGSOUND src=""><img SRC="sound.gif" onClick="play('kookaburras.wav')" ><b><font face="Arial,Helvetica"><font size=-1><font color="#000000">...</font><font color="#FFCC00">WAV
Sound of Aussie Kookaburras Laughing</font></font></font></b>
<p><BGSOUND src=""><img SRC="sound.gif" onClick="play('pretty-girl.mid')" ><b><font face="Arial,Helvetica"><font size=-1><font color="#000000">...</font><font color="#CC33CC">MIDI
Pretty Girl...</font></font></font></b>
<p><BGSOUND src=""><img SRC="sound.gif" onClick="play('stop-play.mid')" ><b><font face="Arial,Helvetica"><font size=-1><font color="#000000">...</font><font color="#FF0000">STOP
PLAY</font></font></font></b>
<br>
<br> </blockquote>
</body>
</html>
....or anyone else who might like to throw 2 cent's worth in :)
Cheers!
KB...
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.