Have sound play when alert is triggered

后端 未结 4 1161
盖世英雄少女心
盖世英雄少女心 2020-12-10 15:20

So I have in my javascript an if statement. When it returns true it opens an alert box and plays an alarm sound. The problem is that the sound doesn\'t play until I hit th

4条回答
  •  感动是毒
    2020-12-10 15:31

    Preload your audio file in the html beforehand like :

    
    
    if(x > 10)
    {
        document.getElementById('xyz').play();
        alert("Thank you!");
    }
    

    This should surely work.

提交回复
热议问题