...

View Full Version : Script to play sound when button is pressed



Avril
05-07-2006, 12:30 PM
Hi!

I found the correct embed script to play a short sound on my Website, but it works when the page opens. However, I would like the sound to play only when the "enter" button is pressed. Searched, but cannot seem to find the solution. Could anyone help me, please? Thank in advance!

kaitco
05-08-2006, 03:10 AM
It is difficult to discern what the exact issue is without seeing your code. You may want to post it just so we can see exactly what you are using.

From what you are describing, it sounds like you may need to switch a portion of the code to read autostart="false", which will make it so that someone will have to press your button in order to hear the sound. Hope this helps!

Avril
05-08-2006, 11:05 AM
Sorry I was not clear:
I have a Web page which opens normally on which I have an "enter" image button taking the visitor to a linked page. Now, when the visitor clicks on the enter button I want the sound to be played and a new page (linked to the button) to open. I inserted the "embed" tags where the button is (like an <a href> tag) , but the sound plays when the page opens and not when the button is pressed. The code probably has to be tweaked, but I cannot find any info anywhere. It would be great if you could help. Thanks.

Avril
05-08-2006, 11:47 AM
It is difficult to discern what the exact issue is without seeing your code. You may want to post it just so we can see exactly what you are using.

From what you are describing, it sounds like you may need to switch a portion of the code to read autostart="false", which will make it so that someone will have to press your button in order to hear the sound. Hope this helps!


Oops, forgot! Here's the code:
<EMBED SRC="drip.au" AUTOSTART=true hidden=true LOOP=1><a href="SBPage2.html"><img src="Images/ButtonEnter.jpg"></a></EMBED>

Arbitrator
05-08-2006, 12:47 PM
If you click the pronunciation (speaker) image on the page linked below, it plays a sound. You could modify that script for your purposes. What it basically does is, it loads the sound in an invisible iframe.

http://www.answers.com/solecism&r=67

I think your main problem will be having the sound play when you click since after clicking to a new page, you're not really at the page you clicked from anymore. You'd probably need to preload the sound and some kind of delay before you go to a new page which could be kind of annoying. It's different from something like Flash where you click to a new page but since you haven't really gone anywhere, the sound plays smoothly.

Btw, don't mind the word I picked. It was just something I was looking up yesterday.

Avril
05-08-2006, 02:44 PM
Is this it?
<span style="cursor:pointer" onmouseover="status='Click to hear pronunciation';return true;" onmouseout="status='';return true;" onclick="playIt('http://content.answers.com/main/content/ahd4/pron/S0546400.wav')">

Bit weak in JS...

bustamelon
05-08-2006, 04:53 PM
That's it, but that's just the call to the function which is here:


<bgsound id="bgs"></bgsound>&nbsp;
<iframe style="height:1px;width:1px;position:absolute;" frameborder="0" id="soundFrame"></iframe>
<script type="text/javascript">
<!--
//hello

var IFrameObj = document.getElementById("soundFrame");
function playIt(soundUrl) {
IFrameObj.src = "about:blank";
IFrameObj.src = soundUrl;
setTimeout("endPlay()", 10000);
}
function endPlay() {
IFrameObj.src = "about:blank"; //so refresh won't replay sound
}

// -->
</script>

Avril
05-08-2006, 05:55 PM
Thanks a ton! Will try it out asap and let you know the result.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum