view raw
dA_uNknOwN dA_uNknOwN - 6 months ago 52
Javascript Question

Javascript Audio Play on click

I have a javascript code to start a sound on click .
It works on chrome but on fireforx it startes onload ,but i want it onclick theire too.
Can anyone help?

var audio = new Audio("http://music.ogg" ) ;

audio.oncanplaythrough = function(){;

audio.loop = true;

audio.onended = function(){;


<input type="image" src="http://button.png" onclick="">


Try this


  function play(){
       var audio = document.getElementById("audio");;

<input type="button" value="PLAY"  onclick="play()">
<audio id="audio" src="" ></audio>