JS判定ブラウザ
2174 ワード
var sUserAgent
function detectOS() {
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");
var isiPhon = (navigator.platform=="iPhone"
|| navigator.platform=="Iphone"
|| navigator.platform=="IPhone"
|| navigator.platform=="iphone");
if (isMac)
return "Mac";
var isUnix = (navigator.platform == "X11") && !isWin && !isMac;
if (isUnix)
return "Unix";
if (isiPhon)
return "iPhone";
var isLinux = (String(navigator.platform).indexOf("Linux") > -1);
var bIsAndroid = sUserAgent.toLowerCase().match(/android/i) == "android";
if (isLinux) {
if (bIsAndroid)
return "Android";
else
return "Linux";
}
if (isWin) {
var isWin2K = sUserAgent.indexOf("Windows NT 5.0") > -1
|| sUserAgent.indexOf("Windows 2000") > -1;
if (isWin2K)
return "Win2000";
var isWinXP = sUserAgent.indexOf("Windows NT 5.1") > -1
|| sUserAgent.indexOf("Windows XP") > -1;
if (isWinXP)
return "WinXP";
var isWin2003 = sUserAgent.indexOf("Windows NT 5.2") > -1
|| sUserAgent.indexOf("Windows 2003") > -1;
if (isWin2003)
return "Win2003";
var isWinVista = sUserAgent.indexOf("Windows NT 6.0") > -1
|| sUserAgent.indexOf("Windows Vista") > -1;
if (isWinVista)
return "WinVista";
var isWin7 = sUserAgent.indexOf("Windows NT 6.1") > -1
|| sUserAgent.indexOf("Windows 7") > -1;
if (isWin7)
return "Win7";
}
return "other";
}
document.writeln(" :" + detectOS()+" </br>sUserAgent:"+sUserAgent
+" </br>navigator.platform:"+navigator.platform );