我想在加载网页 5 秒后播放音频文件。我写了以下代码,但它不起作用。有人可以教我如何在加载网页 5 秒后播放音频文件吗?感谢您的大力帮助。谢谢。
以下代码适用于 IE。我主要想让它适用于 FIREFOX-3.0。在 Firefox 中,我收到一条错误消息,说 'document.getElementById('audiotag1').play' 不是函数。我怎样才能使它适用于Firefox?
<html>
<head>
<script type="text/javascript">
function doTimer(length, resolution, oninstance, oncomplete)
{
var steps = (length / 100) * (resolution / 10),
speed = length / steps,
count = 0,
start = new Date().getTime();
function instance()
{
if(count++ == steps)
{
oncomplete(steps, count);
}
else
{
oninstance(steps, count);
var diff = (new Date().getTime() - start) - (count * speed);
window.setTimeout(instance, (speed - diff));
}
}
window.setTimeout(instance, speed);
}
doTimer(5000, 20, function(steps)
{
},
function() {
document.getElementById('audiotag1').play();
}
);
</script>
<script type="text/javascript">
function play_single_sound() {
document.getElementById('audiotag1').play();
}
</script>
</head>
<body>
Timer out
<audio id="audiotag1" src="https://www.dropbox.com/s/0kf457qwu6zh5q4/warning_alarm.mp3" preload="auto"></audio>
<a href="javascript:play_single_sound();">warning_alarm</a>
</body>
</html>