html5 audio ie,HTML5 Audio not working in ie7 or ie8

问题

When testing in IE7/8 my script crashes and I get this error...

SCRIPT438: Object doesn't support property or method 'play'

I'm using the HTML5 audio tag to embed and play audio on my webpage.

Your browser isn't invited for super fun audio time.

Your browser isn't invited for super fun audio time.

My JS looks like this:

start.click(function(){

audio.play();

});

I've included this in my header:

Does anyone know of any solutions or fixes?

回答1:

Many older browsers including IE7/8 do not (fully) support HTML 5.

You can use Modernizr to detect whether the current browser supports audio.

There are polyfills for many features including audio that can add support for missing features

https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-browser-Polyfills

(scroll down to the Audio section for options)

The polyfills work on a wide range of supported browsers and browser versions.

回答2:

I had a similar problem and here is how I fixed it (this now works in IE8 and plays wav files too!). The trick is to use audio tag for HTML5 compatible browsers and embed tag for older IE ones.

Create two elements in your HTML page:

following is the JavaScript part of playing sound in older as well as newer browsers:

//Returns the version of Windows Internet Explorer or a -1. Available on the Internet!

function getInternetExplorerVersion()

{

var rv = -1; // Return value assumes failure.

if (navigator.appName == 'Microsoft Internet Explorer') {

var ua = navigator.userAgent;

var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");

if (re.exec(ua) != null)

rv = parseFloat(RegExp.$1);

}

return rv;

}

var browserVer = getInternetExplorerVersion();

if (browserVer > -1 && browserVer < 9) {

document.getElementById('audiotagII').play();

} else {

document.getElementById('audiotag').play();

}

Thank you!

回答3:

If the browser does not support HTML5 audio, there is not much you can do besides use a substitute for those browsers. According to w3schools:

Internet Explorer 8 and earlier versions, do not support the

element.

Source: http://www.w3schools.com/html/html5_audio.asp

来源:https://stackoverflow.com/questions/13827637/html5-audio-not-working-in-ie7-or-ie8

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值