1、js判斷移動(dòng)端系統(tǒng)
var userAgent = navigator.userAgent;
// android終端
var isAndroid = userAgent.indexOf('Android') > -1 || userAgent.indexOf('Adr') > -1;
// ios終端
var isIOS = !!userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
2、js判斷是否PC端
function IsPC() {
var userAgent = navigator.userAgent;
var Agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"];
var flag = true;
for (var v = 0; v < Agents.length; v++) {
if (userAgent.indexOf(Agents[v]) > -1) {
flag = false;
break;
}
}
return flag;
}
3蘸拔、js判斷是否為微信內(nèi)置瀏覽器
function isWeiXin() {
var userAgent = window.navigator.userAgent.toLowerCase();
if(userAgent.match(/MicroMessenger/i) == 'micromessenger') {
return true;
} else {
return false;
}
}
4、js判斷是否為ie瀏覽器,并返回相應(yīng)狀態(tài)
function IEVersion() {
// 取得瀏覽器的userAgent字符串
var userAgent = navigator.userAgent;
// 判斷是否IE<11瀏覽器
var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1;
// 判斷是否IE的Edge瀏覽器
var isEdge = userAgent.indexOf("Edge") > -1 && !isIE;
// 判斷是否為IE11瀏覽器
var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1;
if(isIE) {
var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
reIE.test(userAgent);
var fIEVersion = parseFloat(RegExp["$1"]);
if(fIEVersion == 7) {
return 7;
} else if(fIEVersion == 8) {
return 8;
} else if(fIEVersion == 9) {
return 9;
} else if(fIEVersion == 10) {
return 10;
} else {
return 6; // IE版本<=7
}
} else if (isEdge) {
return 'edge'; // edge
} else if (isIE11) {
return 11; // IE11
} else {
return -1; // 不是ie瀏覽器
}
}
5算柳、js判斷瀏覽器內(nèi)核
var browserInfo = {
versions: function () {
var userAgent = navigator.userAgent,
appVersion = navigator.appVersion;
return {
// IE內(nèi)核
trident: userAgent.indexOf('Trident') > -1,
// opera內(nèi)核
presto: userAgent.indexOf('Presto') > -1,
// 蘋果低淡、谷歌內(nèi)核
webKit: userAgent.indexOf('AppleWebKit') > -1,
// 火狐內(nèi)核
gecko: userAgent.indexOf('Gecko') > -1 && userAgent.indexOf('KHTML') == -1,
// 是否為移動(dòng)終端
mobile: !!userAgent.match(/AppleWebKit.*Mobile.*/),
// ios終端
ios: !!userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),
// android終端
android: userAgent.indexOf('Android') > -1 || userAgent.indexOf('Adr') > -1,
// 是否為iPhone或者QQHD瀏覽器
iPhone: userAgent.indexOf('iPhone') > -1,
// 是否iPad
iPad: userAgent.indexOf('iPad') > -1,
// 是否web應(yīng)該程序,沒(méi)有頭部與底部
webApp: userAgent.indexOf('Safari') == -1,
// 是否微信 (2015-01-22新增)
weixin: userAgent.indexOf('MicroMessenger') > -1,
// 是否QQ
qq: userAgent.match(/\sQQ/i) == " qq"
};
},
language:(navigator.browserLanguage || navigator.language).toLowerCase()
}
6、js判斷客戶端操作系統(tǒng)
function detectOS() {
var userAgent = 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") > -1);
if (isLinux) return "Linux";
if (isWin) {
var isWin2K = userAgent.indexOf("Windows NT 5.0") > -1 || userAgent.indexOf("Windows 2000") > -1;
if (isWin2K) return "Win2000";
var isWinXP = userAgent.indexOf("Windows NT 5.1") > -1 || userAgent.indexOf("Windows XP") > -1;
if (isWinXP) return "WinXP";
var isWin2003 = userAgent.indexOf("Windows NT 5.2") > -1 || userAgent.indexOf("Windows 2003") > -1;
if (isWin2003) return "Win2003";
var isWinVista= userAgent.indexOf("Windows NT 6.0") > -1 || userAgent.indexOf("Windows Vista") > -1;
if (isWinVista) return "WinVista";
var isWin7 = userAgent.indexOf("Windows NT 6.1") > -1 || userAgent.indexOf("Windows 7") > -1;
if (isWin7) return "Win7";
var isWin10 = operatingInfo.indexOf("Windows NT 10")!=-1;
if(isWin10) return "Win10"
}
return "other";
}
document.writeln("您的操作系統(tǒng)是:" + detectOS());