判断当前浏览器的版本

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>判断当前浏览器的版本</title>


<script type="text/javascript">
function isIE(){   
return navigator.appName.indexOf("Microsoft Internet Explorer")!=-1 && document.all;   
}   
function isIE6() {   
return navigator.userAgent.split(";")[1].toLowerCase().indexOf("msie 6.0")=="-1"?false:true;   
}   
function isIE7(){   
return navigator.userAgent.split(";")[1].toLowerCase().indexOf("msie 7.0")=="-1"?false:true;   
}   
function isIE8(){   
return navigator.userAgent.split(";")[1].toLowerCase().indexOf("msie 8.0")=="-1"?false:true;   
}   
function isNN(){   
  return navigator.userAgent.indexOf("Netscape")!=-1;   
}   
function isOpera(){   
return navigator.appName.indexOf("Opera")!=-1;   
}   
function isFF(){   
return navigator.userAgent.indexOf("Firefox")!=-1;   
}   
function isChrome(){   
return navigator.userAgent.indexOf("Chrome") > -1;     


function showResult(){
if(isChrome()){
alert("这是谷歌浏览器");
}

if(isIE()){
alert("这是IE");
}

if(isIE6()){
alert("这是isIE6");
}

if(isIE7()){
alert("这是isIE7");
}

if(isIE8()){
alert("这是IisIE8");
}

if(isNN()){
alert("这是isNN");
}

if(isOpera()){
alert("这是isOpera");
}

if(isFF()){
alert("这是isFF");
}
}
</script>




</head>


<body οnlοad="showResult()">
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可以通过以下方法判断当前浏览器版本: 1. 使用 navigator.userAgent 属性获取浏览器信息字符串: ``` var userAgent = navigator.userAgent; ``` 2. 根据不同的浏览器判断规则,解析出浏览器名称和版本号: ``` // 判断是否为IE浏览器 if (userAgent.indexOf("MSIE") != -1 || userAgent.indexOf("Trident") != -1) { // 获取IE版本号 var ieVersion = userAgent.match(/(MSIE|rv:)\s?([\d\.]+)/)[2]; console.log("IE " + ieVersion); } // 判断是否为Edge浏览器 else if (userAgent.indexOf("Edge") != -1) { // 获取Edge版本号 var edgeVersion = userAgent.match(/Edge\/([\d\.]+)/)[1]; console.log("Edge " + edgeVersion); } // 判断是否为Chrome浏览器 else if (userAgent.indexOf("Chrome") != -1) { // 获取Chrome版本号 var chromeVersion = userAgent.match(/Chrome\/([\d\.]+)/)[1]; console.log("Chrome " + chromeVersion); } // 判断是否为Firefox浏览器 else if (userAgent.indexOf("Firefox") != -1) { // 获取Firefox版本号 var firefoxVersion = userAgent.match(/Firefox\/([\d\.]+)/)[1]; console.log("Firefox " + firefoxVersion); } // 判断是否为Safari浏览器 else if (userAgent.indexOf("Safari") != -1) { // 获取Safari版本号 var safariVersion = userAgent.match(/Version\/([\d\.]+)/)[1]; console.log("Safari " + safariVersion); } ``` 注意:以上代码只是简单的示例,实际中可能需要根据具体需求进行修改和完善。同时,由于不同浏览器的 user agent 字符串格式并不相同,因此解析方法也可能存在不同。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值