Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Nov 2005
    Posts
    329
    Thanks
    3
    Thanked 19 Times in 19 Posts

    Question Script to play sound when button is pressed

    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!

  • #2
    Regular Coder
    Join Date
    Dec 2005
    Location
    Ohio
    Posts
    286
    Thanks
    7
    Thanked 9 Times in 9 Posts
    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!

  • #3
    Regular Coder
    Join Date
    Nov 2005
    Posts
    329
    Thanks
    3
    Thanked 19 Times in 19 Posts
    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.

  • #4
    Regular Coder
    Join Date
    Nov 2005
    Posts
    329
    Thanks
    3
    Thanked 19 Times in 19 Posts
    Quote Originally Posted by kaitco
    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>

  • #5
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,387
    Thanks
    32
    Thanked 288 Times in 282 Posts
    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.
    For every complex problem, there is an answer that is clear, simple, and wrong.

  • #6
    Regular Coder
    Join Date
    Nov 2005
    Posts
    329
    Thanks
    3
    Thanked 19 Times in 19 Posts
    Is this it?
    <span style="cursorointer" 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...

  • #7
    Regular Coder
    Join Date
    Mar 2006
    Location
    Connecticut, USA
    Posts
    400
    Thanks
    1
    Thanked 0 Times in 0 Posts
    That's it, but that's just the call to the function which is here:

    Code:
    <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>

  • #8
    Regular Coder
    Join Date
    Nov 2005
    Posts
    329
    Thanks
    3
    Thanked 19 Times in 19 Posts
    Thanks a ton! Will try it out asap and let you know the result.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •