簡體   English   中英

如何在較舊版本的Internet Explorer中支持HTML5音頻標簽?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM