Doesn’t matter what I do, I simply can’t get this to play a sound in Firefox or IE, or Chrome for that matter.
<html>
<head>
<script type="text/javascript">
function play()
{
var embed = document.createElement('object');
embed.setAttribute('src', 'c:\\test.wav');
embed.setAttribute('hidden', true);
embed.setAttribute('autostart', true);
embed.setAttribute('enablejavascript', true);
document.childNodes[0].appendChild(embed);
}
// -->
</script>
</head>
<body onload="play();">
</body>
</html>
Try using this revised version of the function play()
The problem with your code was you were using the src attribute, which is for the <embed> tag. Instead, use the data attribute for the <object> tag.
If you are trying to get the most compatibility out of this, you should also consider adding the embed tag as an alternate for the object tag. The way it works is like this:
This works similar to the noscript tag, where older browsers that don’t support the object tag resort to the embed tag.