(function(window){ var realwall = { detection : (function(){ var ua = navigator.userAgent.toLowerCase(); alert(ua); var pattern = { ie : /^(?!.*?opera)(.*?)msie(.*?)$/, opera : /opera/, safari : /version.*satari/, chrome : /chrome/, firefox : /^(?!.*?webkit)(.*?)gecko(.*?)$/ } var IEVersion = function(ua){ var begin = ua.indexOf('msie'); if(begin < 0){ return 0; }else{ return parseFloat(ua.substring(begin + 5, ua.indexOf(';', begin))); } }; var IE67 = function(ua){ var ieVer = IEVersion(ua); if(ieVer > 5 && ieVer < 8){ return true; }else{ return false; } }; var sysInfo = function(ua){ var begin, win = ua.indexOf('Win'), unix = ua.indexOf('X11'), mac = ua.indexOf('Mac'), linux = ua.indexOf('Linux'); if(win > -1){ begin = win; }else if(unix > -1){ begin = unix; }else if(mac > -1){ begin = mac; }else if(linux > -1){ begin = linux; }else{ return ''; } return ua.substring(begin, ua.indexOf(';', begin)); }; var detection = { isIE : pattern.ie.test(ua), isOpera : pattern.opera.test(ua), isSafari : pattern.safari.test(ua), isChrome : pattern.chrome.test(ua), isFirefox : pattern.firefox.test(ua), getIEVersion : IEVersion(ua), isIE67 : IE67(ua), getSysInfo : sysInfo(navigator.userAgent) } return detection; })() }; window.realwall = realwall; })(window); alert(realwall.detection.getSysInfo);