function getNavigatorInfoStr()
{
var name = navigator.appName, ver = navigator.appVersion,
ver_int = parseInt(navigator.appVersion), ua = navigator.userAgent, infostr;
if(name == "Microsoft Internet Explorer")
{
if(ver.indexOf("MSIE 3.0") != -1) return "Internet Explorer 3.0x";
if(ver_int != 4) return "Internet Explorer " + ver.substring(0, ver.indexOf(" "));
var real_ver = parseInt(ua.substring(ua.indexOf("MSIE ") + 5));
if(real_ver >= 7) infostr = "Windows Internet Explorer ";
else infostr = "Microsoft Internet Explorer ";
if(ua.indexOf("MSIE 5.5") != -1) return infostr + "5.5";
else return infostr + real_ver + ".x";
return "Internet Explorer";
}
else if(name == "Netscape")
{
if(parseInt(ua.substring(8, 8)) <= 4)
return "Netscape " + ver.substring(0, ver.indexOf(" "));
else if(ua.lastIndexOf(" ") < ua.lastIndexOf("/"))
return ua.substring(ua.lastIndexOf(" "));
else return "Netscape";
}
else return name;
}
function getOSInfoStr()
{
var ua = navigator.userAgent;
if(ua.indexOf("NT 6.0") != -1) return "Windows Vista/Server 2008";
else if(ua.indexOf("NT 5.2") != -1) return "Windows Server 2003";
else if(ua.indexOf("NT 5.1") != -1) return "Windows XP";
else if(ua.indexOf("NT 5.0") != -1) return "Windows 2000";
else if(ua.indexOf("NT") != -1) return "Windows NT";
else if(ua.indexOf("9x 4.90") != -1) return "Windows Me";
else if(ua.indexOf("98") != -1) return "Windows 98";
else if(ua.indexOf("95") != -1) return "Windows 95";
else if(ua.indexOf("Win16") != -1) return "Windows 3.x";
else if(ua.indexOf("Windows") != -1) return "Windows";
else if(ua.indexOf("Linux") != -1) return "Linux";
else if(ua.indexOf("Macintosh") != -1) return "Macintosh";
else return "";
}
그냥 재미로 짜봤습니다. 유용할 거라고 믿어요.
테스트 환경:
Windows Vista, Internet Explorer 7.0
Windows Server 2008, Internet Explorer 7.0
Windows Me, Internet Explorer 5.5
Windows Vista, Firefox 3.0b2
Windows Vista, Firefox 2.0.0.10
Windows Vista, Netscape Navigator 9.0
Windows Vista, Mozilla SeaMonkey 1.1.6
Ubuntu 7.04, Firefox 2.0.0.10
물론 테스트 환경에서 잘못 나온 건 없었습니다.
- Safari, Konqueror 등에서 appName, appVersion, userAgent가 어떻게 되는지 알려주세요! -