Created
September 11, 2012 08:06
-
-
Save batako/3696815 to your computer and use it in GitHub Desktop.
OS判定
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 OS(){ | |
var OS, ua = navigator.userAgent; | |
// Windows 7 | |
if (ua.match(/Win(dows )?NT 6\.1/)) { | |
OS = "Windows 7"; | |
} | |
// Windows Vista | |
else if (ua.match(/Win(dows )?NT 6\.0/)) { | |
OS = "Windows Vista"; | |
} | |
// Windows Server 2003 | |
else if (ua.match(/Win(dows )?NT 5\.2/)) { | |
OS = "Windows Server 2003"; | |
} | |
// Windows XP | |
else if (ua.match(/Win(dows )?(NT 5\.1|XP)/)) { | |
OS = "Windows XP"; | |
} | |
// Windows ME | |
else if (ua.match(/Win(dows)? (9x 4\.90|ME)/)){ | |
OS = "Windows ME"; | |
} | |
// Windows 2000 | |
else if (ua.match(/Win(dows )?(NT 5\.0|2000)/)){ | |
OS = "Windows 2000"; | |
} | |
// Windows 98 | |
else if (ua.match(/Win(dows )?98/)){ | |
OS = "Windows 98"; | |
} | |
// Windows NT | |
else if (ua.match(/Win(dows )?NT( 4\.0)?/)){ | |
OS = "Windows NT"; | |
} | |
// Windows 95 | |
else if (ua.match(/Win(dows )?95/)){ | |
OS = "Windows 95"; | |
} | |
// Apple | |
else if (ua.match(/Mac|PPC/)){ | |
// iPhone | |
if (ua.match(/iPhone/)){ | |
OS = "iPhone"; | |
} | |
// iPad | |
else if (ua.match(/iPad/)){ | |
OS = "iPad"; | |
} | |
// iPod | |
else if (ua.match(/iPod/)){ | |
OS = "iPod"; | |
} | |
// Macintosh | |
else{ | |
OS = "Mac OS"; | |
} | |
} | |
// Linux | |
else if (ua.match(/Linux/)){ | |
OS = "Linux"; | |
} | |
// BSD系 | |
else if (ua.match(/(Free|Net|Open)BSD/)){ | |
OS = RegExp.$1 + "BSD"; | |
} | |
// Solaris | |
else if (ua.match(/SunOS/)){ | |
OS = "Solaris"; | |
} | |
// 上記以外のOS | |
else{ | |
OS = "N/A"; | |
} | |
return(OS); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment