JS判断浏览器类型,JS判断客户端操作系统

时间:2023-02-04 09:16:02

JS判断浏览器类型

function judge(){
var browser = {
versions: function() {
var u = navigator.userAgent, app = navigator.appVersion;
return {//移动终端浏览器版本信息
trident: u.indexOf('Trident') > -, //IE内核
presto: u.indexOf('Presto') > -, //opera内核
webKit: u.indexOf('AppleWebKit') > -, //苹果、谷歌内核
gecko: u.indexOf('Gecko') > - && u.indexOf('KHTML') == -, //火狐内核
mobile: !!u.match(/AppleWebKit.*Mobile.*/) || !!u.match(/AppleWebKit/), //是否为移动终端
ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
android: u.indexOf('Android') > - || u.indexOf('Linux') > -, //android终端或者uc浏览器
iPhone: u.indexOf('iPhone') > - || u.indexOf('Mac') > -, //是否为iPhone或者QQHD浏览器
iPad: u.indexOf('iPad') > -, //是否iPad
webApp: u.indexOf('Safari') == - //是否web应该程序,没有头部与底部
};
}(),
language: (navigator.browserLanguage || navigator.language).toLowerCase()
}
console.log(browser.language)
if (browser.versions.ios || browser.versions.iPhone || browser.versions.iPad) {
// window.location="www.zhongsou.com";
}else if (browser.versions.android) {
// window.location="http://www.baidu.com";
}
/*window.location.href="https://itunes.apple.com/us/app/ma-ma-fan-er/id985525130?mt=8&uo=4";*/
}
var bb=new judge();

JS判断客户端操作系统

function detectOS() {
var sUserAgent = navigator.userAgent;
var isWin = (navigator.platform == "Win32") || (navigator.platform == "Windows");
var isMac = (navigator.platform == "Mac68K") || (navigator.platform == "MacPPC") || (navigator.platform == "Macintosh") || (navigator.platform == "MacIntel");
if (isMac) return "Mac";
var isUnix = (navigator.platform == "X11") && !isWin && !isMac;
if (isUnix) return "Unix";
var isLinux = (String(navigator.platform).indexOf("Linux") > -);
if (isLinux) return "Linux";
if (isWin) {
var isWin2K = sUserAgent.indexOf("Windows NT 5.0") > - || sUserAgent.indexOf("Windows 2000") > -;
if (isWin2K) return "Win2000";
var isWinXP = sUserAgent.indexOf("Windows NT 5.1") > - || sUserAgent.indexOf("Windows XP") > -;
if (isWinXP) return "WinXP";
var isWin2003 = sUserAgent.indexOf("Windows NT 5.2") > - || sUserAgent.indexOf("Windows 2003") > -;
if (isWin2003) return "Win2003";
var isWinVista= sUserAgent.indexOf("Windows NT 6.0") > - || sUserAgent.indexOf("Windows Vista") > -;
if (isWinVista) return "WinVista";
var isWin7 = sUserAgent.indexOf("Windows NT 6.1") > - || sUserAgent.indexOf("Windows 7") > -;
if (isWin7) return "Win7";
}
return "other";
} document.writeln("您的操作系统是:" + detectOS());