js 如何判断 谷歌与火狐浏览器 本人JS比较菜 麻烦各位给指点下 谢谢...

发布网友 发布时间:2025-01-08 00:33

我来回答

3个回答

热心网友 时间:2分钟前

这段代码很早之前在网上搜到的,忘了出处了
<script language="javascript" type="text/javascript">
function userAgent(){
var ua = navigator.userAgent;
ua = ua.toLowerCase();
var match = /(webkit)[ \/]([\w.]+)/.exec(ua) ||
/(opera)(?:.*version)?[ \/]([\w.]+)/.exec(ua) ||
/(msie) ([\w.]+)/.exec(ua) ||
!/compatible/.test(ua) && /(mozilla)(?:.*? rv:([\w.]+))?/.exec(ua) ||
[];
//match[2]判断版本号
switch(match[1]){
case "msie": //ie
if (parseInt(match[2]) == 6) //ie6
alert("ie6");
else if (parseInt(match[2]) == 7) //ie7
alert("ie7");
else if (parseInt(match[2]) == 8) //ie8
alert("ie8");
break;
case "webkit": //safari or chrome
alert("safari or chrome");
break;
case "opera": //opera
alert("opera");
break;
case "mozilla": //Firefox
alert("Firefox");
break;
default:
break;
}
}
userAgent();
</script>

热心网友 时间:5分钟前

使用navigator的userAgent
请看参考资料

热心网友 时间:4分钟前

获取浏览器的ua就可以了

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com