js判断浏览器版本 2009年10月30日 星期五 16:09 js判断浏览器版本及版本号,本代码支持最新的ie7,ie8,firefox2,firefox3的判断
<script>
window["MzBrowser"]={};(function()
{
if(MzBrowser.platform) return;
var ua = window.navigator.userAgent;
MzBrowser.platform = window.navigator.platform;
MzBrowser.firefox = ua.indexOf("Firefox")>0;
MzBrowser.opera = typeof(window.opera)=="object";
MzBrowser.ie = !MzBrowser.opera && ua.indexOf("MSIE")>0;
MzBrowser.mozilla = window.navigator.product == "Gecko";
MzBrowser.netscape= window.navigator.vendor=="Netscape";
MzBrowser.safari= ua.indexOf("Safari")>-1;
if(MzBrowser.firefox) var re = /Firefox(\s|\/)(\d+(\.\d+)?)/;
else if(MzBrowser.ie) var re = /MSIE( )(\d+(\.\d+)?)/;
else if(MzBrowser.opera) var re = /Opera(\s|\/)(\d+(\.\d+)?)/;
else if(MzBrowser.netscape) var re = /Netscape(\s|\/)(\d+(\.\d+)?)/;
else if(MzBrowser.safari) var re = /Version(\/)(\d+(\.\d+)?)/;
else if(MzBrowser.mozilla) var re = /rv(\:)(\d+(\.\d+)?)/;
if("undefined"!=typeof(re)&&re.test(ua))
MzBrowser.version = parseFloat(RegExp.$2);
})();
function abc()
{
if(MzBrowser.ie)
{
alert('ie');
}
if(MzBrowser.firefox)
{
alert('firefox');
}
alert(MzBrowser.version);
}
abc();
</script>
javascript判断浏览器版本
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=gb2312">
<title>JS 判断浏览器</title>
</head>
<body>
<hr>
<!--判断访问者的浏览器(类型)以及版本-->
<script type="text/javascript">
var browser=navigator.appName
var b_version=navigator.appVersion
var version=parseFloat(b_version)
document.write("Browser name: "+ browser)
document.write("
")
document.write("Browser version: "+ version)
</script>
<hr>
<!--更多有关访问者浏览器(详细信息)-->
<script type="text/javascript">
document.write("Browser: ")
document.write(navigator.appName + "")
document.write("Browserversion: ")
document.write(navigator.appVersion + "")
document.write("Code: ")
document.write(navigator.appCodeName + "")
document.write("Platform: ")
document.write(navigator.platform + "")
document.write("Cookies enabled: ")
document.write(navigator.cookieEnabled + "")
document.write("Browser's user agent header: ")
document.write(navigator.userAgent + "")
</script>
<hr>
<!--所有信息-->
<script type="text/javascript">
var x = navigator
document.write("CodeName=" + x.appCodeName)
document.write("
")
document.write("MinorVersion=" + x.appMinorVersion)
document.write("
")
document.write("Name=" + x.appName)
document.write("
")
document.write("Version=" + x.appVersion)
document.write("
")
document.write("CookieEnabled=" + x.cookieEnabled)
document.write("
")
document.write("CPUClass=" + x.cpuClass)
document.write("
")
document.write("OnLine=" + x.onLine)
document.write("
")
document.write("Platform=" + x.platform)
document.write("
")
document.write("UA=" + x.userAgent)
document.write("
")
document.write("BrowserLanguage=" + x.browserLanguage)
document.write("
")
document.write("SystemLanguage=" + x.systemLanguage)
document.write("
")
document.write("UserLanguage=" + x.userLanguage)
</script>
<hr>
<!--依据浏览器来提示用户-->
<script type="text/javascript">
var browser=navigator.appName
var b_version=navigator.appVersion
var version=parseFloat(b_version)
if ((browser=="Netscape"||browser=="Microsoft Internet Explorer") && (version>=4))
{
document.write("Your browser is good enough!")
}
else
{
document.write("It's time to upgrade your browser!")
}
</script>
</body>
</html>