码迷,mamicode.com
首页 > Web开发 > 详细

如何利用js识别不同的浏览器

时间:2017-09-22 11:55:35      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:color   rip   browser   代码   识别   比较   cape   百度   bsp   

如果想测试某个浏览器的特征可以通过如下方法获取

JS获取浏览器信息
浏览器代码名称:navigator.appCodeName
浏览器名称:navigator.appName
浏览器版本号:navigator.appVersion
对Java的支持:navigator.javaEnabled()
MIME类型(数组):navigator.mimeTypes
系统平台:navigator.platform
插件(数组):navigator.plugins
用户代理:navigator.userAgent

比较全的

 1 <script type="text/javascript"> 
 2 document.write(‘浏览器判別:‘);
 3 var OsObject=navigator.userAgent;
 4 // 包含「Opera」文字列 
 5 if(OsObject.indexOf("Opera") != -1) 
 6 { 
 7    document.write(‘您的浏览器是Opera吧?‘); 
 8 } 
 9 // 包含「MSIE」文字列 
10 else if(OsObject.indexOf("MSIE") != -1) 
11 { 
12    document.write(‘您的浏览器是Internet Explorer吧?‘); 
13 } 
14 // 包含「chrome」文字列 ,不过360浏览器也照抄chrome的UA
15  
16 else if(OsObject.indexOf("Chrome") != -1) 
17 { 
18   document.write(‘您的浏览器是chrome或360浏览器吧?‘); 
19 }
20 // 包含「UCBrowser」文字列 
21 else if(OsObject.indexOf("UBrowser") != -1) 
22 { 
23   document.write(‘您的浏览器是UBrowser吧?‘); 
24 }
25 // 包含「BIDUBrowser」文字列 
26 else if(OsObject.indexOf("BIDUBrowser") != -1) 
27 { 
28   document.write(‘您的浏览器是百度浏览器吧?‘); 
29 }
30 // 包含「Firefox」文字列 
31 else if(OsObject.indexOf("Firefox") != -1) 
32 { 
33   document.write(‘您的浏览器是Firefox吧?‘); 
34 }
35 // 包含「Netscape」文字列 
36 else if(OsObject.indexOf("Netscape") != -1)
37 { 
38   document.write(‘您的浏览器是Netscape吧?‘); 
39 } 
40 // 包含「Safari」文字列 
41 else if(OsObject.indexOf("Safari") != -1) 
42 { 
43    document.write(‘您的浏览器是Safari 吧?‘); 
44 } 
45 else{ 
46   document.write(‘无法识别的浏览器。‘); 
47 } 
48 </script>

 

如何利用js识别不同的浏览器

标签:color   rip   browser   代码   识别   比较   cape   百度   bsp   

原文地址:http://www.cnblogs.com/i-want-to-be-like-an-sun/p/7573664.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!