Created
June 17, 2016 04:17
-
-
Save zhiqiang21/3686459d6d7e7246cb32f9b57e6dd54c to your computer and use it in GitHub Desktop.
判断当前访问者的客户端设备类型、操作系统及浏览器类型
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 判断当前访问者的客户端设备类型、操作系统及浏览器类型 | |
function jupmBrowserType() { | |
var browser = { | |
versions: function () { | |
var u = navigator.userAgent, app = navigator.appVersion; | |
return { // 客户端浏览器版本信息 | |
trident: u.indexOf('Trident') > -1, // IE内核 | |
webKit: u.indexOf('AppleWebKit') > -1, // 苹果、谷歌内核 | |
mobile: !!u.match(/AppleWebKit.*Mobile.*/), // 是否为移动终端 | |
android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, // android终端或者uc浏览器 | |
iPhone: u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1 // 是否为iPhone或者QQHD浏览器 | |
}; | |
} () | |
} | |
// 是否为移动终端 | |
if (!browser.versions.mobile) { | |
// 是否为IE内核 | |
if (browser.versions.trident) { | |
return 4; | |
} else if (browser.versions.webKit) { // 是否为苹果、谷歌内核 | |
return 1; | |
} else { | |
return 0; | |
} | |
} else { | |
// 是否为android终端 | |
if (browser.versions.android) { | |
return 2; | |
} else if (browser.versions.iPhone) { //是否为iPhone终端 | |
return 3; | |
} else { | |
return 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment