Possible Duplicate:
Playing sound notifications using Javascript?
I’m making a game in JS, and I need a proper way to play a sound when something happens. How do you do that with JS/HTML5? I saw this article, but even with their example, it doesn’t really work! Sometimes I do hear that bird, but only for a short time, and I can’t get it to work anymore then.
You can make use of the HTML5
<audio>tag: http://jsfiddle.net/STTnr/.HTML:
Just hide the element itself:
Do note that no browser supports all formats. This can be frustrating, but you can supply your audio in several formats.