Bgsound onclick() javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Muhammad Qaiser
    New Member
    • Dec 2010
    • 6

    Bgsound onclick() javascript

    Dears
    I am trying to run a simple bgsound script. But i dont know why its not working. The code is as follows.
    Code:
    <script language="javascript">
    function changeBgSound(arg){
    document.getElementById("mysound").src=arg;
    }
    </script>
    <body>
    <bgsound id="mysound" src="cphfinan.wav">
    
    <a href="soundtest.html" onClick="changeBgSound('cphfinan.wav')"><img src="favicon.ico"></a>
    
    </body>
    I would be extremely obliged for anyone's favourable response in this regard.

    Thanks & Regards
    Muhammad Qaiser
  • RamananKalirajan
    Contributor
    • Mar 2008
    • 608

    #2
    Whether this HTML file is soundtest.html?

    Thanks and Regards
    Ramanan Kalirajan

    Comment

    • Muhammad Qaiser
      New Member
      • Dec 2010
      • 6

      #3
      Yes you are right. its the same file.

      Comment

      • rnd me
        Recognized Expert Contributor
        • Jun 2007
        • 427

        #4
        bgsound is a really old way to do play audio in JavaScript; im surprised you can hear anything at all.

        you can try changing the A's href from href="soundtest .html" ta href="#" and see if that helps, but i think bgsound is loaded upon pageload, and so it won't reload until the page does.

        use the <audio> tag to play sound, falling back to <embed>.

        Comment

        • Muhammad Qaiser
          New Member
          • Dec 2010
          • 6

          #5
          thanks alot for your response. i have done the same using javascript.

          Anyways thaaanks alot to both the responders.

          Regards

          Comment

          Working...