请问如何用js判断是何种浏览器?
3个回答
展开全部
var browername = "";
var browerversion = "";
$(document).ready(function () {//页面加载事件
//Jquery新特征
var browerinfo = navigator.userAgent.toLowerCase();
if (/msie/.test(browerinfo))
{
browername = "Ie";
猜手旁browerversion = getversiong(browerinfo, "msie");
}
if (/firefox/.test(browerinfo))
{
browername = "Mozilla Firefox ";
browerversion = getversiong(browerinfo, "firefox");
}
if (/safari/.test(browerinfo))
{
browername = "Apple Safari ";
browerversion = getversiong(browerinfo, "safari");
}
if (/chrome/.test(browerinfo))
{
browername = "Google";
browerversion = getversiong(browerinfo, "chrome");
}
if(/opr/.test(browerinfo))
{
browername = "Opera ";
browerversion = getversiong(browerinfo, "opr");
}
//alert(browername+","+browerversion);
})
function getversiong(browerinfo,obj)//获取浏览器的版本号
{
switch (obj)
{
case "msie":
var nameversion = browerinfo.substring(browerinfo.indexOf(obj));
穗橡 var version = nameversion.substring(nameversion.search(/ /g)+1, nameversion.indexOf(";"));
break;
case "firefox":
var nameversion = browerinfo.substring(browerinfo.indexOf(obj));
var version = nameversion.substring(nameversion.indexOf("/") + 1);
break;
case "safari":
var nameversion = browerinfo.substring(browerinfo.indexOf(obj));
var version = nameversion.substring(nameversion.indexOf("/") + 1);
break;
case "chrome":
var nameversion = browerinfo.substring(browerinfo.indexOf(obj));
薯御 var version = nameversion.substring(nameversion.indexOf("/") + 1, nameversion.search(/ /g) + 1);
break;
case "opr":
var nameversion = browerinfo.substring(browerinfo.indexOf(obj));
var version = nameversion.substring(nameversion.indexOf("/") + 1);
break;
}
return version;
}
function getbrowerinfo()
{
return browername +":"+ browerversion;
}
2015-07-21
展开全部
您好!很高兴为您答疑慧模冲!
代码如前歼下:
<script language="JavaScript" type="text/javascript">
if ((navigator.userAgent.indexOf('MSIE') >= 0) && (navigator.userAgent.indexOf('Opera') < 0)){alert('你是使用IE'码伏)}else
if (navigator.userAgent.indexOf('Firefox') >= 0){alert('你是使用Firefox')}else
if (navigator.userAgent.indexOf('Opera') >= 0){alert('你是使用Opera')}else
{alert('你是使用其他的浏览器浏览网页!')}
</script>
代码如前歼下:
<script language="JavaScript" type="text/javascript">
if ((navigator.userAgent.indexOf('MSIE') >= 0) && (navigator.userAgent.indexOf('Opera') < 0)){alert('你是使用IE'码伏)}else
if (navigator.userAgent.indexOf('Firefox') >= 0){alert('你是使用Firefox')}else
if (navigator.userAgent.indexOf('Opera') >= 0){alert('你是使用Opera')}else
{alert('你是使用其他的浏览器浏览网页!')}
</script>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
navigator.useragent来判断,具体去网上找资料
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询