[英]Detecting MP3 support in a page for old browser
I'm writing an mp3 playlist player, and I'm almost done... but, I would like to make the page compatible with older browser (people with older browsers will see a simple list of mp3 links: they can download them, it's not a problem).我正在编写一个 mp3 播放列表播放器,我快完成了......但是,我想让页面与旧浏览器兼容(使用旧浏览器的人会看到一个简单的 mp3 链接列表:他们可以下载它们,这不是问题)。 Now, I'm afraid I have some problem with javascript syntax, rather than with some specific command.
现在,恐怕我对 javascript 语法有一些问题,而不是某些特定命令。 So, this is my code:
所以,这是我的代码:
ilikemp3 = 0; if (document.createElement('audio').canPlayType('audio/mpeg;codecs="mp3"')) {ilikemp3 = 1}; if (ilikemp3) {audio_playlist_html5()} else {simple_audio_list()};
It's working fine on modern browsers... but, if I run it in older browsers, I get an error message:它在现代浏览器上运行良好......但是,如果我在旧浏览器中运行它,我会收到一条错误消息:
Error: document.createElement("audio").canPlayType is not a function错误:document.createElement("audio").canPlayType 不是函数
So, I understand that's not the proper way to query a browser.所以,我知道这不是查询浏览器的正确方法。 Can somebody help me?
有人可以帮助我吗? Thanks a lot!
非常感谢!
You could check for the existence of canPlayType
in document.createElement('audio')
and decide based on that.您可以检查
document.createElement('audio')
是否存在canPlayType
并据此做出决定。
if('canPlayType' in document.createElement('audio')) {
//new player
}
else {
//old player
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.