When a certain event occurs, I want my website to play a short notification sound to the user.
The sound should not auto-start (instantly) when the website is opened.
Instead, it should be played on demand via JavaScript (when that certain event occurs).
It is important that this also works on older browsers (IE6 and such).
So, basically there are two questions:
- What codec should I use?
- What’s best practice to embed the audio file? (
<embed>vs.<object>vs. Flash vs.<audio>)
2023 solution
Browser support
Edge 12+, Firefox 20+, Internet Explorer 9+, Opera 15+, Safari 4+, Chrome
Codecs Support
Just use MP3
Old solution
(for legacy browsers)
Browser support
<audio>(Modern browsers)<embed> (Fallback)Codes used