Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can I play a short pop noise when a user clicks on a link? 1

Status
Not open for further replies.

frkitten99

Programmer
Feb 21, 2005
6
US
I have an hyperlinked image. When a user clicks on this image, I'd like to open another small window that displays a full size version of this image AND make a short "pop" noise.

How the heck can I do that? Do I need to do this in flash or anything or can I use dynamic html/javascript/html...and how?
 
I can think of a couple of ways, but they are unwieldy. Can I try to disuade you without sounding "preachy"? On at least a windows platform, those kinds of noises aren't up to the coder, they are up to the user. They can be turned on or off. Thus, users are trained to expect to have "navigational noises" under their control. That means such things are part of the "user model" or "user expectation". Anything that BREAKS the user model is bound to have negative consequences.

I am sure you want to do this because you think it would enhance the experience of your site, when in fact in would almost certainly do just the opposite.

Nope, I sounded preachy. Ah, well.

Thomas D. Greer
 
I'd agree with Thomas - just leave it up to the user. I have my browser set to make a click sound when I click on a link, but I wouldn't want anybody to change that. Worse, I might end up with BOTH sounds, and that would make me REALLY annoyed.

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
This may be what you need. This uses an array so you can use more than one sound.
Code:
<html><head><script LANGUAGE="JavaScript"><!--

var aySound = new Array();

aySound[0] = [COLOR=red]"pop.wav";[/color]
aySound[1] = "work.wav";
aySound[2] = "cheap.wav";
document.write('<BGSOUND ID="auIEContainer">')
IE = (navigator.appVersion.indexOf("MSIE")!=-1 && document.all)? 1:0;
NS = (navigator.appName=="Netscape" && navigator.plugins["LiveAudio"])? 1:0;
ver4 = IE||NS? 1:0;
onload=auPreload;

function auPreload() {
if (!ver4) return;
if (NS) auEmb = new Layer(0,window);
else {
Str = "<DIV ID='auEmb' STYLE='position:absolute;'></DIV>";
document.body.insertAdjacentHTML("BeforeEnd",Str);
}
var Str = '';
for (i=0;i<aySound.length;i++)
Str += "<EMBED SRC='"+aySound[i]+"' AUTOSTART='FALSE' HIDDEN='TRUE'>"
if (IE) auEmb.innerHTML = Str;
else {
auEmb.document.open();
auEmb.document.write(Str);
auEmb.document.close();
}
auCon = IE? document.all.auIEContainer:auEmb;
auCon.control = auCtrl;
}
function auCtrl(whSound,play) {
if (IE) this.src = play? aySound[whSound]:'';
else eval("this.document.embeds[whSound]." + (play? "play()":"stop()"))
}
function playSound(whSound) { if (window.auCon) auCon.control(whSound,true); }
function stopSound(whSound) { if (window.auCon) auCon.control(whSound,false); }
//-->
</script>
  

</head><body><a href="HomePage.htm" [COLOR=red]onFocus="playSound(0)" onBlur="stopSound(0)"[/color]
<a href="2Page.htm" [COLOR=red]onFocus="playSound(1)" onBlur="stopSound(1)"[/color]></body</html>
You can also use the onclick event handlerfor this, I use onfocus/blur in case the sound file is a long one and the user wants to stop it.

Glen
 
tgreer and tsdragon:

I agree that it should be left up to the user, but I'm doing this at the request of a customer. If it were my own site, I'd leave out bells and whistles such as that, as I myself find it annoying.

glenmac: Thanks. I haven't tried it out yet, but will get to it. I suppose this goes in the page that actually pops up?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top