ITeye博客

判断浏览器版本

yangzisai · 2011-08-10 08:12 · web前端 · Web前端 · Markdown

使用

navigator对象的userAgent属性

返回客户发送到服务器的user_agent的头部的值

根据特性来判定:

IE:mozilla/4.0 (compatible; msie 6.0; windows nt 5.2; sv1; .net clr 1.1.4322; infopath.2; .net clr 2.0.50727; .net clr 3.0.04506.30)

 

FireFox:mozilla/5.0 (windows; u; windows nt 5.2; zh-cn; rv:1.9.2.12) gecko/20101026 firefox/3.6.12

 

Opera:opera/9.80 (windows nt 5.2; u; edition ibis; zh-cn) presto/2.6.30 version/10.62

 

所以:navigator.userAgent.toLowerCase()

统一转换为小写

然后navigator.useAgent.toLowerCase().index("mise") != -1;

navigator.useAgent.toLowerCase().index("firefox") != -1;

navigator.useAgent.toLowerCase().index("opera") != -1

来分别判断出对应的浏览器

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。