JS 判断获取当前系统类型

可用来定义某些WIN7系统和XP系统下字体区别
在WIN7系统下和XP系统下的宋体显示是不一样的、有的时候容易撑破格子
而且WIN7下面微软雅黑是系统自带的、效果很好!
以下的代码可以方便我们判断不同的系统在使用不同系统里自带效果好的字体!或者其它一些东西!

<script type="text/javascript" >
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") > -1);
if (isLinux) 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 isWin2003 = sUserAgent.indexOf("Windows NT 6.0") > -1 || sUserAgent.indexOf("Windows Vista") > -1;
if (isWin2003) return "WinVista";
var isWin2003 = sUserAgent.indexOf("Windows NT 6.1") > -1 || sUserAgent.indexOf("Windows 7") > -1;
if (isWin2003) return "Win7";
}
return "other";
}
</script>

http://www.cnblogs.com/banbu/archive/2011/10/26/2225890.html

THE END
分享
二维码
打赏
< <上一篇
下一篇>>