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 3 of 3
  1. #1
    New Coder
    Join Date
    Dec 2010
    Posts
    66
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Play sound onMouseOver

    Just so you know: this is not my idea, the person whose site this is wants a short blip sound played whenever you roll over the links in the sidebar. I know it's not advised, but she insists.

    So can anybody tell me how this is done? I've tried implementing a few scripts but no luck in Firefox or Chrome.

    Thanks.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,081
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    As you say, this is very ill-advised, but if your client really insists on driving people away from her website:-


    WORKS IN IE and FIREFOX and SAFARI
    Place the following script in the <head> of your HTML document:

    Code:
    <script type="text/javascript">
    function playSound(soundfile) {
    document.getElementById("dummy").innerHTML="<embed src=\""+ soundfile +"\" hidden=\"true\" autostart=\"true\" loop=\"false\" />";
    }
    </script>
    The Sound is Placed in an Empty Span<br>
    The JavaScript places an embed tag inside an empty span tag when the script is initiated. So, you need to add the following span file somewhere within the body of your HTML page, preferably near the top of the document:

    Code:
    <span id="dummy"></span>
    Call the script with an onmouseover or onclick Attribute.
    The last thing you need to add is an element that you want to generate the sound on click or on mouseover. Call the script with one of those attributes:-

    Code:
    <a href="#" onclick="playSound('URL to soundfile');">Click here to hear a sound</a>
    
    <p onmouseover="playSound('URL to soundfile');">Mouse over this text to hear a sound</p>

    "I'm all in favour of keeping dangerous weapons out of the hands of fools. Let's start with typewriters." - Frank Lloyd Wright

  • Users who have thanked Philip M for this post:

    JumpJump (12-24-2010)

  • #3
    New Coder
    Join Date
    Dec 2010
    Posts
    66
    Thanks
    16
    Thanked 0 Times in 0 Posts
    Thanks a lot. Appreciate it. Hopefully I'll never have to use it again.


  •  

    Posting Permissions

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