JavaScript判断浏览器类型

 
 1         function ceshi() {
 2      
 3             var browserName = navigator.userAgent.toLowerCase();
 4             if (/msie/i.test(browserName) && !/opera/.test(browserName)) {
 5                 alert("IE");
 6                 return;
 7             } else if (/firefox/i.test(browserName)) {
 8                 alert("Firefox");
 9                 return;
10             } else if (/chrome/i.test(browserName) && /webkit/i.test(browserName) && /mozilla/i.test(browserName)) {
11                 alert("Chrome");
12                 return;
13             } else if (/opera/i.test(browserName)) {
14                 alert("Opera");
15                 return;
16             } else if (/webkit/i.test(browserName) && !(/chrome/i.test(browserName) && /webkit/i.test(browserName) && /mozilla/i.test(browserName))) {
17                 alert("Safari");
18                 return;
19             } else {
20                 alert("unKnow");
21             }
22 
23         }
View Code

 

posted @ 2014-02-14 14:20  Jbp  阅读(608)  评论(0编辑  收藏  举报