检测浏览器(比如IE)的版本号码是Web 开发最常遇到的问题之一, 以下总结几种检测IE版本号码的方法:
通过Javascript解释浏览器的 User-Agent 字符串:
Javascript代码
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 );
}
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渲染引擎的的当前渲染模式:
Javascript代码
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.
}
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 对象:
C-sharp代码
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;
}
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的扩展注释语句:
Xhtml代码
<!--[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]>
分享到:
相关推荐
1.3 JavaScript的版本 1.4 一些值得留意的特性 禁忌及如何突破这些禁忌 1.5 安全性和执行效率 1.6 一个例子--JavaScript编写的计算器 1.7 学习和使用JavaScript的几点建议 1.8 关于本书的...
Chrome Frame 会把最新版的Chrome Webkit 内核和JavaScript 引擎注入到IE中, IE浏览器将获得Chrome的性能和功能 目录 摘要 I ABSTRACT II 专业名词清单 III 第一章 绪论 1 1.1 研究背景与意义 1 1.2国内外相关...
在javascript编程中,开发者通常需要编写很多小程序来实现一些特定的功能。例如浏览器检测,字符串处理、数组的编辑等。jQuery对这些常用的程序进行了...version 浏览器的版本号 在使用时,开发者可以直接调用这些属性
调用ie接口。主要的代码在IEComCtrlSink中。 sqlite3使用 引用了Splayer中的Sqlite3库,进行了测试。 SrcFirstProg 简单的窗口程序。 SuperGrid - 特别的 listview 控件 网格形式的视图,自绘了CComboBox、CEdit...
这个例子就是查询任何可执行文件的版本信息并且 C++builder 和 VC 都通用,只需要把 AnsiString 替换成 CString 就行了。 gh0st v3.6 源码 - 可下断点调试! 如题。详细见源码。 GMem 内存管理单元源码。GMem.cpp...
调用ie接口。主要的代码在IEComCtrlSink中。 sqlite3使用 引用了Splayer中的Sqlite3库,进行了测试。 SrcFirstProg 简单的窗口程序。 SuperGrid - 特别的 listview 控件 网格形式的视图,自绘了CComboBox、CEdit...
调用ie接口。主要的代码在IEComCtrlSink中。 sqlite3使用 引用了Splayer中的Sqlite3库,进行了测试。 SrcFirstProg 简单的窗口程序。 SuperGrid - 特别的 listview 控件 网格形式的视图,自绘了CComboBox、CEdit...
调用ie接口。主要的代码在IEComCtrlSink中。 sqlite3使用 引用了Splayer中的Sqlite3库,进行了测试。 SrcFirstProg 简单的窗口程序。 SuperGrid - 特别的 listview 控件 网格形式的视图,自绘了CComboBox、CEdit...
调用ie接口。主要的代码在IEComCtrlSink中。 sqlite3使用 引用了Splayer中的Sqlite3库,进行了测试。 SrcFirstProg 简单的窗口程序。 SuperGrid - 特别的 listview 控件 网格形式的视图,自绘了CComboBox、CEdit...
三、在Windows XP Home版本中添加IIS的方法一般情况下按照“一”的方法只适用于Windows XP的专业版本,而对于家庭版,如今已有了破解方法:步骤1 首先我们需要准备一张Windows 2000的安装光盘,假设你的Windows XP...
小编的确一直都想把这方面的命令做个总结,这次辛苦老范给我们整理了这份实用的秘笈。 Bootcfg bootcfg 命令启动配置和故障恢复(对于大多数计算机,即 boot.ini 文件)。 含有下列参数的 bootcfg 命令仅在...