js判断浏览器,并输出想要的css
展开全部
<script 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>
互次元:http://www.hcy9.com
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>
互次元:http://www.hcy9.com
展开全部
<html>
<body>
<script type="text/javascript">
var browser=navigator.appName
var b_version=navigator.appVersion
var version=parseFloat(b_version)
document.write("浏览器名称:"+ browser)
document.write("<br />")
document.write("浏览器版本:"+ version)
</script>
</body>
</html>
<body>
<script type="text/javascript">
var browser=navigator.appName
var b_version=navigator.appVersion
var version=parseFloat(b_version)
document.write("浏览器名称:"+ browser)
document.write("<br />")
document.write("浏览器版本:"+ version)
</script>
</body>
</html>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询