I am new to javascript and want to make sure I am on the right track when playing a sound. Is there anything I should not be doing better or not be doing at all. Below is a simple function.
<script language="javascript" type="text/javascript">
function playSound(soundfile) {
if (navigator.userAgent.indexOf('Firefox') != -1) {
document.getElementById("dummy").innerHTML = "<embed src=\"" + soundfile + "\" hidden=\"true\" autostart=\"true\" loop=\"false\" type=\"application/x-mplayer2\" />";
} else {
document.getElementById("dummy").innerHTML = "<embed src=\"" + soundfile + "\" hidden=\"true\" autostart=\"true\" loop=\"false\" />";
}
}
</script>
</head>
<body>
<span id="dummy"></span>
<a href="#" onclick="playSound('doorbell.wav');">Click here to hear a sound</a>
</body>
I am not sure whether I should be using the audio tag or not. I appreciate any feedback
embedinstead ofaudio? – unor Feb 12 at 9:03