Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/462.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在旧版本的Internet Explorer中支持HTML5音频标记?_Javascript_Html_Internet Explorer_Audio - Fatal编程技术网

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使用了
标记在那里有一个回退