检测IE版本号的方法总结
2009-07-22 14:01
381 查看
检测浏览器(比如IE)的版本号码是Web 开发最常遇到的问题之一, 以下总结几种检测IE版本号码的方法:
通过Javascript解释浏览器的 User-Agent 字符串:
通过Javascript判断IE渲染引擎的的当前渲染模式:
通过ASP.NET 的 HttpBrowserCapabilities 对象:
通过HTML的扩展注释语句:
通过Javascript解释浏览器的 User-Agent 字符串:
function getInternetExplorerVersion() // Returns the version of Internet Explorer or a -1 // (indicating the use of another browser). { var rv = -1; // Return value assumes failure. if (navigator.appName == 'Microsoft Internet Explorer') { var ua = navigator.userAgent; var re = new RegExp("MSIE ([0-9]{1,}[/.0-9]{0,})"); if (re.exec(ua) != null) rv = parseFloat( RegExp.$1 ); } return rv; } function checkVersion() { var msg = "You're not using Internet Explorer."; var ver = getInternetExplorerVersion(); if ( ver > -1 ) { if ( ver >= 8.0 ) msg = "You're using a recent copy of Internet Explorer." else msg = "You should upgrade your copy of Internet Explorer."; } alert( msg ); }
通过Javascript判断IE渲染引擎的的当前渲染模式:
engine = null; if (window.navigator.appName == "Microsoft Internet Explorer") { // This is an IE browser. What mode is the engine in? if (document.documentMode) // IE8 engine = document.documentMode; else // IE 5-7 { engine = 5; // Assume quirks mode unless proven otherwise if (document.compatMode) { if (document.compatMode == "CSS1Compat") engine = 7; // standards mode } } // the engine variable now contains the document compatibility mode. }
通过ASP.NET 的 HttpBrowserCapabilities 对象:
private float getInternetExplorerVersion() { // Returns the version of Internet Explorer or a -1 // (indicating the use of another browser). float rv = -1; System.Web.HttpBrowserCapabilities browser = Request.Browser; if (browser.Browser == "IE") rv = (float)(browser.MajorVersion + browser.MinorVersion); return rv; } private void Page_Load(object sender, System.EventArgs e) { string msg; double ver = getInternetExplorerVersion(); if (ver > 0.0) { if (ver >= 7.0) msg = "You're using a recent version of Internet Explorer."; else msg = "You should upgrade your copy of Internet Explorer."; } else msg = "You're not using Internet Explorer."; Label1.Text = msg; }
通过HTML的扩展注释语句:
<!--[if gte IE 8]> <p>You're using a recent version of Internet Explorer.</p> <![endif]--> <!--[if lt IE 7]> <p>Hm. You should upgrade your copy of Internet Explorer.</p> <![endif]--> <![if !IE]> <p>You're not using Internet Explorer.</p> <![endif]>
相关文章推荐
- 检测IE版本号的方法总结
- [Web开发] 检测IE版本号的方法总结
- [Web开发] 检测IE版本号的方法总结
- 检测IE版本号的方法总结
- 总结:在IE中加入信任/受限站点的方法
- js浏览器和浏览器插件检测的方法总结(二)
- php检测字符串编码(utf-8,gbk,gb2312)是否为utf8编码的方法总结
- Firefox和IE兼容性问题及解决方法总结
- IE和Firefox(火狐)在JavaScript方面的不兼容及统一方法总结
- js高级程序设计(第三版)总结--检测数组(判断数组的方法)
- 基于深度学习的目标检测方法总结
- 解决IE被恶意修改方法总结
- 总结一下js判断是否为ie的方法
- 检测PC端和移动端的方法总结
- 目标检测中背景建模方法总结
- linux 检测远程端口是否打开方法总结
- Spring&Hibernate增删改方法总结,版本号V1.0.0(献给纠结于SSH框架的学子们)
- vs中内存泄漏检测的方法总结
- IE和Firefox 在JavaScript方面的不兼容及统一方法总结
- 浏览器兼容之旅第四站:IE常见Bug总结及修复方法―part2