返回用户代理头的字符串表示(就是包括浏览器版本信息等的字符串)
语法:
navigator.userAgent
几种浏览的user_agent.,像360的兼容模式用的是IE、极速模式用的是chrom的内核。
浏览器 | userAgent |
chrome | Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebkit/537.36 (KHTML, like Gecko)Chrome/34.0.1847.116 Safari/537.36 |
firefox | Mozilla/5.0 (Windows NT 6.1; WOW64;rv:24.0) Gecko/20100101 Firefox/24.0 |
IE 8 | Mozilla/4.0 (compatible; MSIE 8.0 Windows NT 6.1; WOW64; Trident/4.0; SLCC2;.NET CLR2.0.50727;.NET CLR 3.5.30729;.NET CLR 3.0.30729;.NET4.0C) |
使用userAgent判断使用的是什么浏览器(假设使用的是IE8浏览器),代码如下:
function validB(){ var u_agent = navigator.userAgent; var B_name="Failed to identify the browser"; if(u_agent.indexOf("Firefox")>-1){ B_name="Firefox"; }else if(u_agent.indexOf("Chrome")>-1){ B_name="Chrome"; }else if(u_agent.indexOf("MSIE")>-1&&u_agent.indexOf("Trident")>-1){ B_name="IE(8-10)"; } document.write("B_name:"+B_name+"<br>"); document.write("u_agent:"+u_agent+"<br>");
Trident(图形接口的排版引擎) 又称为MSHTML是微软的窗口操作系统(Windows)搭载的网页浏览器—Internet Explorer的排版引擎的名称。
MSIE(Microsoft Internet Explorer)是微软公司推出的一款网页浏览器。