检测浏览器信息

 

重要事项:在 IE 5.0 及以后版本中,版本号是不正确的!在 IE 5.0 和 IE 6.0 中,微软为 appVersion 字符串赋的值是 4.0。怎么会出现这样的错误呢?无论如何,我们需要清楚的是,JavaScript 在 IE6、IE5 和 IE4 中的获得的版本号是相同的。

 

检测浏览器及版本

<html>
<body>
<script type="text/javascript">
var browser=navigator.appName
var b_version=navigator.appVersion
var version=parseFloat(b_version)
document.write(
"浏览器名称:"+ browser)
document.write(
"<br />")
document.write(
"浏览器版本:"+ version)
</script>
</body>
</html>

 

 

 

 检测浏览器的更多信息

 

<html>
<body>
<script type="text/javascript">
document.write(
"<p>浏览器:")
document.write(navigator.appName
+ "</p>")

document.write(
"<p>浏览器版本:")
document.write(navigator.appVersion
+ "</p>")

document.write(
"<p>代码:")
document.write(navigator.appCodeName
+ "</p>")

document.write(
"<p>平台:")
document.write(navigator.platform
+ "</p>")

document.write(
"<p>Cookies 启用:")
document.write(navigator.cookieEnabled
+ "</p>")

document.write(
"<p>浏览器的用户代理报头:")
document.write(navigator.userAgent
+ "</p>")
</script>
</body>
</html>

 

 

结果:

浏览器:Microsoft Internet Explorer

浏览器版本:4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)

代码:Mozilla

平台:Win32

Cookies 启用:true

浏览器的用户代理报头:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)

 

 

检测浏览器的全部信息

 

<html>
<body>

<script type="text/javascript">
var x = navigator;
document.write(
"CodeName=" + x.appCodeName);
document.write(
"<br />");
document.write(
"MinorVersion=" + x.appMinorVersion);
document.write(
"<br />");
document.write(
"Name=" + x.appName);
document.write(
"<br />");
document.write(
"Version=" + x.appVersion);
document.write(
"<br />");
document.write(
"CookieEnabled=" + x.cookieEnabled);
document.write(
"<br />");
document.write(
"CPUClass=" + x.cpuClass);
document.write(
"<br />");
document.write(
"OnLine=" + x.onLine);
document.write(
"<br />");
document.write(
"Platform=" + x.platform);
document.write(
"<br />");
document.write(
"UA=" + x.userAgent);
document.write(
"<br />");
document.write(
"BrowserLanguage=" + x.browserLanguage);
document.write(
"<br />");
document.write(
"SystemLanguage=" + x.systemLanguage);
document.write(
"<br />");
document.write(
"UserLanguage=" + x.userLanguage);
</script>

</body>
</html>

 

结果:

CodeName=Mozilla
MinorVersion=;SP2;
Name=Microsoft Internet Explorer
Version=4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)
CookieEnabled=true
CPUClass=x86
OnLine=true
Platform=Win32
UA=Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)
BrowserLanguage=zh-cn
SystemLanguage=zh-cn
UserLanguage=zh-cn

 

根据浏览器类型提醒用户

 

<html>
<head>
<script type="text/javascript">
function detectBrowser()
{
var browser=navigator.appName
var b_version=navigator.appVersion
var version=parseFloat(b_version)
if ((browser=="Netscape"||browser=="Microsoft Internet Explorer") && (version>=4))
{alert(
"您的浏览器够先进了!")}
else
{alert(
"是时候升级您的浏览器了!")}
}
</script>
</head>

<body onload="detectBrowser()">
</body>

</html>

 

posted @ 2010-10-12 17:16  xfyn  阅读(283)  评论(0编辑  收藏  举报