<mce:script type="text/javascript" language="javascript"><!-- $(function () { //【简单写法】 var Sys = {}; var ua = navigator.userAgent.toLowerCase(); if (window.ActiveXObject) Sys.ie = ua.match(/msie ([/d.]+)/)[1] else if (document.getBoxObjectFor) Sys.firefox = ua.match(/firefox//([/d.]+)/)[1] else if (window.MessageEvent && !document.getBoxObjectFor) Sys.chrome = ua.match(/chrome//([/d.]+)/)[1] else if (window.opera) Sys.opera = ua.match(/opera.([/d.]+)/)[1] else if (window.openDatabase) Sys.safari = ua.match(/version//([/d.]+)/)[1]; //测试代码 if(Sys.ie) document.write('IE: '+Sys.ie); if(Sys.firefox) document.write('Firefox: '+Sys.firefox); if(Sys.chrome) document.write('Chrome: '+Sys.chrome); if(Sys.opera) document.write('Opera: '+Sys.opera); if(Sys.safari) document.write('Safari: '+Sys.safari); /*【更精简的写法】 var Sys = {}; var ua = navigator.userAgent.toLowerCase(); window.ActiveXObject ? Sys.ie = ua.match(/msie ([/d.]+)/)[1] : document.getBoxObjectFor ? Sys.firefox = ua.match(/firefox//([/d.]+)/)[1] : window.MessageEvent && !document.getBoxObjectFor ? Sys.chrome = ua.match(/chrome//([/d.]+)/)[1] : window.opera ? Sys.opera = ua.match(/opera.([/d.]+)/)[1] : window.openDatabase ? Sys.safari = ua.match(/version//([/d.]+)/)[1] : 0; //测试代码 if(Sys.ie) document.write('IE: '+Sys.ie); if(Sys.firefox) document.write('Firefox: '+Sys.firefox); if(Sys.chrome) document.write('Chrome: '+Sys.chrome); if(Sys.opera) document.write('Opera: '+Sys.opera); if(Sys.safari) document.write('Safari: '+Sys.safari); */ /* 【更高效的写法】 var Sys = {}; var ua = navigator.userAgent.toLowerCase(); var s; (s = ua.match(/msie ([/d.]+)/)) ? Sys.ie = s[1] : (s = ua.match(/firefox//([/d.]+)/)) ? Sys.firefox = s[1] : (s = ua.match(/chrome//([/d.]+)/)) ? Sys.chrome = s[1] : (s = ua.match(/opera.([/d.]+)/)) ? Sys.opera = s[1] : (s = ua.match(/version//([/d.]+).*safari/)) ? Sys.safari = s[1] : 0; //测试代码 if (Sys.ie) document.write('IE: ' + Sys.ie); if (Sys.firefox) document.write('Firefox: ' + Sys.firefox); if (Sys.chrome) document.write('Chrome: ' + Sys.chrome); if (Sys.opera) document.write('Opera: ' + Sys.opera); if (Sys.safari) document.write('Safari: ' + Sys.safari); */ }); // --></mce:script>
转自:http://www.cnblogs.com/leadzen/archive/2008/09/06/1285764.html