![](/img/trans.png)
[英]HTML5 <audio> tags donesn't work on Firefox and Internet Explorer
[英]How to support HTML5 audio tag in older versions of Internet Explorer?
我正在嘗試使用將autoplay
設置為true
audio
標簽來播放簡單的音頻文件。 它在chrome,firefox中工作正常,但在Internet Explorer的舊版本中沒有運氣。 如何解決呢?
我正在嘗試的代碼:
<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>
我知道IE9以下不支持HTML5音頻。 我不希望Flash回退,因為用戶可能未安裝Flash Player。 在這個場景中,您會采取什么方法?
我發現<bgsound>
標記僅受IE支持。 它達到了我的目的。
對於支持IE:
<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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.