How do I play sound from JavaScript?

Discussion in 'JavaScript' started by sparkar17, Mar 25, 2010.

  1. #1
    How do I play sound from JavaScript?
     
    sparkar17, Mar 25, 2010 IP
  2. mnvlxxx

    mnvlxxx Peon

    Messages:
    47
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can try this:

    
    <script>
    function EvalSound(soundobj) {
      var thissound=document.getElementById(soundobj);
      thissound.Play();
    }
    </script>
    
    <embed src="success.wav" autostart=false width=0 height=0 id="sound1"
    enablejavascript="true">
    
    
    <form>
    <input type="button" value="Play Sound" onClick="EvalSound('sound1')">
    </form>
    
    Code (markup):
     
    mnvlxxx, Mar 25, 2010 IP