Results 1 to 2 of 2

Thread: Problem with javascript text

  1. #1
    Join Date
    Nov 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Problem with javascript text

    1) Script Title:

    2) Script URL (on DD):

    3) Describe problem: see below

    I am not very good at writing javascript code so I am hoping that someone on this forum can help. Here is my situation.
    On the Home page of my web site I have have the following code to send the user from the Home page to my Intro page:

    <p><a href="intro.htm" > Enter </a></p>

    Is it possible, using javascript, to also add a sound effect to this action? I have a sound effect in a "wave" file that I would like to hear when I click on "Enter".

    As it is now I have the following in web site root folder:
    -a javascript folder called "jsscripts"
    -a wave file called "meow.wav"

    I found the following javascript in the Dynamic Drive library:

    <bgsound src="#" id="soundeffect" loop=1 autostart="true" />
    <script type="text/javascript">

    /***********************************************
    * JavaScript Sound effect- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
    * Visit http://www.dynamicDrive.com for hundreds of DHTML scripts
    * This notice must stay intact for legal use
    ***********************************************/

    var soundfile="sidebar.wav" //path to sound file, or pass in filename directly into playsound()

    function playsound(soundfile){
    if (document.all && document.getElementById){
    document.getElementById("soundeffect").src="" //reset first in case of problems
    document.getElementById("soundeffect").src=soundfile
    }
    }

    function bindsound(tag, soundfile, masterElement){
    if (!window.event) return
    var source=event.srcElement
    while (source!=masterElement && source.tagName!="HTML"){
    if (source.tagName==tag.toUpperCase()){
    playsound(soundfile)
    break
    }
    source=source.parentElement
    }
    }
    </script>

    I want to save the above javascript in my "jsscripts" folder by the file name "meow.js" and have this call my wave file when I click on "Enter".

    What changes do I have to make to the above javascript and to my own current html to make my sound effect work? I have played around with the "onClick" function but am still missing something.

    Hopefully I have provided you with enough information.
    Thanks

  2. #2
    Join Date
    Aug 2004
    Posts
    10,143
    Thanks
    3
    Thanked 1,008 Times in 993 Posts
    Blog Entries
    16

    Default

    Firstly, you should be aware this script only works in IE. To get it to activate onclick, you should be able to do this just by changing the keyword onmouseover inside the HTML to onclick instead, for example:

    Code:
    <a href="#" onClick="playsound(soundfile)">Example 1</a>
    
    <a href="#" onClick="playsound('different.wav')">Example 2</a>
    DD Admin

Bookmarks

Posting Permissions

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