文档详情

JS判断浏览器类型及版本(国外英文资料).doc

发布:2017-06-06约1.32万字共19页下载文档
文本预览下载声明
JS判断浏览器类型及版本(国外英文资料) Heres a set of judgments: The function getExplorer () { Var explorer = window.navigator. / / ie If (explorer. IndexOf ( MSIE ) = 0) Alert ( ie ); } / / firefox Else if (explorer. IndexOf ( Firefox ) = 0) { Alert ( Firefox ); } / / Chrome Else if ( Chrome ) ( Chrome ) Alert ( Chrome ); } / / Opera Else if ( Opera ) Alert ( Opera ); } / / Safari Else if ( Safari ) ( Safari ) ( Safari ) ( Safari ) ( Safari)) Alert ( Safari ); } } Method one: In the development of the web site, the browser compatibility issue has already left us scrambling and we dont know how much its going to add to our mess. Browser compatibility is a front-end development framework to solve the first question, to solve the compatibility problems have to be accurately judge the first browser types and versions. JavaScript is the primary language for front-end development, and we can write JavaScript programs to determine the type and version of the browser. JavaScript browser types generally has two ways, one is based on the unique attributes to identify the various browser, another kind is judged through the analysis of the userAgent property of the browser. In many cases, the value judgment of the browser type, still need to determine the browser version to handle compatibility issues, and determine the browser version of the general can only be known through the analysis of the userAgent of browser. Lets first analyze the features of various browsers and their userAgent. IE Only IE supports creating ActiveX controls, so she has something that other browsers dont have, which is the ActiveXObject function. As long as you judge that the window object has an ActiveXObject function, it is clear that the current browser is IE. And the typical userAgent for each version of IE is as follows: Mozilla / 4.0 (compatible; MSIE 8.0; Windows NT 6.0) Mozilla / 4.0 (compatible; MSIE 7.0; Windows NT 5.2) Mozilla / 4.0 (compatible; MSIE 6.0; Windows NT 5.1) Mozilla / 4.0 (compatible; MSIE 5.0
显示全部
相似文档