Javascript 如何在旧版本的Internet Explorer中支持HTML5音频标记?
我正在尝试使用Javascript 如何在旧版本的Internet Explorer中支持HTML5音频标记?,javascript,html,internet-explorer,audio,Javascript,Html,Internet Explorer,Audio,我正在尝试使用audio标记播放一个简单的音频文件,并将autoplay设置为true。它在chrome和firefox中运行良好,但在InternetExplorer的旧版本中却没有成功。如何解决这个问题 我正在尝试的代码: <html> <head> </head> <body> <div id="sound_notification"></div> <button id="playButton" onclick=
audio
标记播放一个简单的音频文件,并将autoplay
设置为true
。它在chrome和firefox中运行良好,但在InternetExplorer的旧版本中却没有成功。如何解决这个问题
我正在尝试的代码:
<html>
<head>
</head>
<body>
<div id="sound_notification"></div>
<button id="playButton" onclick="messageNotification()">Play</button>
<script>
//TODO sound notification for incoming message
function messageNotification()
{
console.log("inside notification handler");
var filename="sound/notify";
document.getElementById("sound_notification").innerHTML='<audio autoplay="autoplay"><source src="' + filename + '.mp3" type="audio/mpeg" /><source src="' + filename + '.ogg" type="audio/ogg" /><embed hidden="true" autostart="true" loop="false" src="' + filename +'.mp3" /></audio>';
}
</script>
</body>
</html>
<html>
<head>
</head>
<body>
<!-- this tag is only supported by IE -->
<bgsound id="notification">
<button id="playButton" onclick="messageNotification()">Play</button>
<script>
//TODO sound notification for incoming message
function messageNotification()
{
document.getElementById("notification").src="sound/notify.mp3";
}
</script>
</body>
</html>
玩
//传入消息的TODO声音通知
函数messageNotification()
{
log(“内部通知处理程序”);
var filename=“声音/通知”;
document.getElementById(“声音通知”).innerHTML='';
}
我知道IE9下不支持HTML5音频。我不希望flash倒退,因为用户可能没有安装flash player。在这个场景中,你会采取什么方法?我找到了只受IE支持的
标签。它符合我的目的
支持IE:
<html>
<head>
</head>
<body>
<div id="sound_notification"></div>
<button id="playButton" onclick="messageNotification()">Play</button>
<script>
//TODO sound notification for incoming message
function messageNotification()
{
console.log("inside notification handler");
var filename="sound/notify";
document.getElementById("sound_notification").innerHTML='<audio autoplay="autoplay"><source src="' + filename + '.mp3" type="audio/mpeg" /><source src="' + filename + '.ogg" type="audio/ogg" /><embed hidden="true" autostart="true" loop="false" src="' + filename +'.mp3" /></audio>';
}
</script>
</body>
</html>
<html>
<head>
</head>
<body>
<!-- this tag is only supported by IE -->
<bgsound id="notification">
<button id="playButton" onclick="messageNotification()">Play</button>
<script>
//TODO sound notification for incoming message
function messageNotification()
{
document.getElementById("notification").src="sound/notify.mp3";
}
</script>
</body>
</html>
玩
//传入消息的TODO声音通知
函数messageNotification()
{
document.getElementById(“notification”).src=“sound/notify.mp3”;
}
因为HTML5
不支持Internet explorer 9或below@ubercooluk起初我也这么认为,但是OP使用了
标记在那里有一个回退