View Full Version : Adding sound to a hyperlink
c03mo
02-26-2007, 05:14 PM
Hi can anyone help, how do you add or embed sound to a hyperlink.
So if press the hyperlink and before the page load i want the sound to go on.
Please let me know if anyone can help me.
thank you
thetestingsite
02-26-2007, 05:30 PM
Probably the best (or most successful) way would be to use Flash. Perhaps javascript could do it, but it might cause errors in certain browsers. As far as plain HTML goes, you will not be able to do it.
Hope this helps.
c03mo
02-26-2007, 06:08 PM
How would i do it JScripts.
can you give an example showing me hyperlink with a sound clip please.
thanks
mburt
02-26-2007, 08:34 PM
Okay, I fiddled around with this a bit and discovered that no matter which way you pull it, you can't change the "src" attribute for an embed. The only way I could see how to do it was like this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Music Player</title>
<script type="text/javascript">
function play(file) {
var plist = document.getElementById("playarea");
plist.innerHTML = '<embed src="'+file+'">';
}
</script>
</head>
<body>
<div id="playarea">
<embed src="mysong1.mp3">
</div>
<br><a href="javascript:play('mysong2.mp3')">play song</a>
</body>
</html>
c03mo
02-26-2007, 09:04 PM
What i wanted was
the text is called log out. now if i click on that text it will take me to another page (href=http//:www.www.com). before that loads up i want the sound to go on. (.wav file).
thats what im looking for.
Please show me how to do that.
thanks
BLiZZaRD
02-26-2007, 09:08 PM
Simple answer... you can't. Even using a server side language, you are trying to make the browser do two things, in two different spots at once.
For example, you are telling the browser to parse this sound on click, okay we can do that. You can also tell the browser to go to another page on click. Sure. But telling browser to go to page X, WHILE playing sound from page Y... nope.
As stated, you can do it in a Flash movie, but without a ton of coding, know how and confusing jargon.. you can't.
I wont tell you it's impossible, but I can tell you there isn't a ready made script that will do this (at least not one that will work proper.)
Demonicman
02-26-2007, 11:13 PM
well, what you can do is create a page... sound.html for instance... and link your href to it, then embed a quick sound on that top play and add java to make it redirect in like 2 seconds... other than that you got me
thetestingsite
02-26-2007, 11:18 PM
add java to make it redirect in like 2 seconds...
You mean javascript. :)
Demonicman
02-26-2007, 11:40 PM
and spell out the entire word? pfft yea right :P
BLiZZaRD
02-26-2007, 11:43 PM
Well considering they are 2 completely different languages, it makes a HUGE difference. Of course you could have just typed "JS" and saved another 2 letters...
Demonicman
02-26-2007, 11:45 PM
:O your right!
techno_race
02-27-2007, 04:14 AM
well, what you can do is create a page... sound.html for instance... and link your href to it, then embed a quick sound on that top play and add java to make it redirect in like 2 seconds... other than that you got me
Indeed.
You don't even need a JavaScript for that! You can do it with plain HTML!
If you plan for your page to be viewed only in Internet Explorer, link to sound.htm and make sound.htm:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<bgsound src="wakamole.wav">
<meta http-equiv="refresh" content="2;URL=http://your.domain.info/youdo/figure_it_out" />
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<iframe src="http://your.domain.info/youdo/figure_it_out" frameborder="0" width="100%" height="100%" scrolling="yes"></iframe>
</body>
</html>
Where 2 is how long the sound is; wakamole.wav is the sound file and http://your.domain.info/youdo/figure_it_out is the page you wanted to link to.
Otherwise, remove <bgsound src="wakamole.wav"> and add
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="32" height="32">
<param name="movie" value="wakamole.wav" />
<param name="quality" value="high" />
<embed src="wakamole.wav" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="32" height="32"></embed>
</object>
inbetween <body> and <iframe>.
PS. NEVER say JScript instead of JS or JavaScript! JScript is Internet Explorer's JavaScript interpreter. Like FF isn't Firefox. Firefox is FX.:mad:
mburt
02-27-2007, 11:03 AM
The link must be clicked before the song is executed. The <bgsound> also only works in IE, and that object automatically plays. Try this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Music Player</title>
<script type="text/javascript">
var delay = 2000;
function play(file) {
var plist = document.getElementById("playarea");
plist.innerHTML = '<embed src="'+file+'">';
setTimeout(function() {redirect();},delay);
}
function redirect() {
window.location.href = "http://www.google.ca/";
}
</script>
</head>
<body>
<div id="playarea">
<embed src="leaves.mp3" autoplay="false">
</div>
<br><a href="javascript:play('alexis.mp3')">play song</a>
</body>
</html>
techno_race
02-28-2007, 12:03 AM
Sorry - I misunderstood c03mo. I thought he wanted the page to load at the same time the sound plays. In this case, remove
<iframe src="http://your.domain.info/youdo/figure_it_out" frameborder="0" width="100%" height="100%" scrolling="yes"></iframe>
from sound.htm. Instead of <bgsound> in the <head> try:
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="32" height="32">
<param name="movie" value="wakamole.wav" />
<param name="quality" value="high" />
<embed src="wakamole.wav" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="32" height="32"></embed>
</object>
in the <body>! Hope this helps, c03mo!
techno_race
03-01-2007, 01:03 AM
Or, replace the iframe but change http://your.domain.info/youdo/figure_it_out to the URL of the webpage with an extra '#iframegoto' at the end. Add <a name="iframegoto" id="iframegoto"> just before <a href="sound.htm">.
Moglizorz
03-02-2007, 07:50 PM
Yes, I agree with the others. Either a 'middle-man' page that has an embedded sound that redirects, or make a flash button that has a 'button object', and on the 'mouse-over' frame it has a sound embedded in a movie object, if you get XFire ( http://files.moglizorz.com/XFire/ ) and add me on it, I am o0mogli0o I will be happy to make the flash button for you. I have been doing it for a couple of years now.
and spell out the entire word? pfft yea right :P
Lol... I like your lazyness :P
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.