网站首页
高清电影
无损音乐
游戏攻略
电脑教程
破解资源
站长资源
软件下载
JS判断浏览器类型与版本的实现代码
(编辑:jimmy 日期: 2024/10/11 浏览:
2
)
在众多的浏览器产品中,IE、Firefox、Opera、Safari........众多品牌却标准不一,因此时常需要根据不同的浏览器,甚至相同浏览器不同版本做不同的操作,因此,知晓浏览器的判断方法,还是很重要的。下面列举一下常用的判断方法
1、判断浏览器是否为IE
document.all ? 'IE' : 'others':在IE下document.all值为1,而其他浏览器下的值为0;
navigator.userAgent.indexOf("MSIE")>0 ? 'IE' : 'others':navigator.userAgent是描述用户代理信息。
navigator.appName.indexOf("Microsoft") != -1 ? 'IE' : 'others':navigator.appName描述浏览器名称信息。
2、判断IE版本
navigator.appVersion.match(/6./i)=="6." ? 'IE6' : 'other version':在已知是IE浏览器的情况下,可以通过此方法判断是否是IE6;
navigator.userAgent.indexOf("MSIE 6.0")>0 ? 'IE7' : 'other version':同上;
navigator.appVersion.match(/7./i)=="7." ? 'IE7' : 'other version':在已知是IE浏览器的情况下,可以通过此方法判断是否是IE7;
navigator.userAgent.indexOf("MSIE 7.0")>0 ? 'IE7' : 'other version':同上;
navigator.appVersion.match(/8./i)=="8." ? 'IE8' : 'other version':在已知是IE浏览器的情况下,可以通过此方法判断是否是IE8;
navigator.userAgent.indexOf("MSIE 8.0")>0 ? 'IE8' : 'other version':同上。
3、JS获取浏览器信息
浏览器代码名称:navigator.appCodeName
浏览器名称:navigator.appName
浏览器版本号:navigator.appVersion
对Java的支持:navigator.javaEnabled()
MIME类型(数组):navigator.mimeTypes
系统平台:navigator.platform
插件(数组):navigator.plugins
用户代理:navigator.userAgent
DEMO:
Js代码
[Ctrl+A 全选 注:引入外部Js需再刷新一下页面才能执行]
上一篇:
分享一道笔试题[有n个直线最多可以把一个平面分成多少个部分]
下一篇:
利用谷歌地图API获取点与点的距离的js代码
最新资源
万代南梦宫逼迫中国选手弃权《铁拳》比赛 国籍不
《黑神话》官方手办引热议:真的很好看真的买不起
《黑神话:悟空》取景地灵岩寺现巨型悟空!挥舞大
秦咏.1997-歌咏诗情·历年名曲典故【音乐谷】【W
群星.1997-纯电影·电影歌曲剧照纪念篇【新艺宝】
邰肇玫.1981-雪歌(滚石25周年经典复刻系列)【滚
《Duck Side of the Moon》特色玩法介绍
《刀郎 辉煌10年绝版珍藏 3CD》[WAV/分轨][1.6G
《张韶涵 全面沦陷》[WAV/分轨][370MB]
《极品汽车音乐 三十而立 一起走过的岁月 2CD》
首页
音乐
电影
资源