JS判断浏览器版本示例

发布时间:2019-09-20编辑:脚本学堂
分享一个js判断浏览器版本的实例代码,学习下js脚本检测浏览器版本信息的方法,有需要的朋友参考下。

1,页面调用
 

复制代码 代码示例:
<html>
<head>
<title>JS判断浏览器版本_www.jb200.com</title>
<script src="GetBrwsVsion.js" type="text/javascript"></script>
<script type="text/javascript">
alert(GetBrowserVersion());
</script>
</head>
<body>
<form>
</form>
</body>
</html>

2,JS方法
 

复制代码 代码示例:
//检测与判断浏览器版本
function GetBrowserVersion()
{
var Sys = {};
var ua = navigator.userAgent.toLowerCase();
window.ActiveXObject ? Sys.ie = ua.match(/msie ([d.]+)/)[1] :
document.getBoxObjectFor ? Sys.firefox = ua.match(/firefox/([d.]+)/)[1] :
window.MessageEvent && !document.getBoxObjectFor ? Sys.chrome = ua.match(/chrome/([d.]+)/)[1] :
window.opera ? Sys.opera = ua.match(/opera.([d.]+)/)[1] :
window.openDatabase ? Sys.safari = ua.match(/version/([d.]+)/)[1] : 0;
if(Sys.ie) return('IE: '+Sys.ie);
if(Sys.firefox)return('FF:'+Sys.firefox);
if(Sys.chrome) return('CH:'+Sys.chrome);
if(Sys.opera) return('OP:'+Sys.opera);
if(Sys.safari) return('SA:'+Sys.safari);
}
/**
IE:IE浏览器;FF:Firefox 火狐浏览器;CH:Chrome,谷歌;OP:Opera浏览器;SA:Safari浏览器
**/