5-3,为什么在chrome打开却提示说是safari?
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>userAgent</title>
</head>
<body>
<input type="button" value="点击获取浏览器信息" id="browser">
<script type="text/javascript">
var btn=document.getElementById("browser");
btn.onclick= function (){
var explorer=navigator.userAgent.toLowerCase(),browser;
if (explorer.indexOf("msie")>-1) {
browser="IE";
}else if (explorer.indexOf("firefox")>-1) {
browser="Firefox";
}else if (explorer.indexOf("safari")>-1) {
browser="Safari";
}else if (explorer.indexOf("chrome")>-1) {
browser="Chrome";
}
return alert("您使用的浏览器是:"+browser+"浏览器")
}
</script>
</body>
</html>
</script>
</body>
</html>
正在回答 回答被采纳积分+1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | <!DOCTYPE html> <html> <head> <meta charset= "UTF-8" > <title>userAgent</title> </head> <body> <input type= "button" value= "点击获取浏览器信息" id= "browser" > <script type= "text/javascript" > var btn=document.getElementById( "browser" ); // 函数封装 function getBrowser(){ var explorer = navigator.userAgent,browser; if (explorer.indexOf( "MISE" )>-1){ browser= "IE" ; } else if (explorer.indexOf( "Safari" )>0 && explorer.indexOf( "Chrome" )<0){ browser= "Safari" ; } else if (explorer.indexOf( "Chrome" )>0){ browser= "Chrome" ; } else if (explorer.indexOf( "Opera" )>-1){ browser= "Opera" ; } return browser; } btn.onclick= function (){ var explorer=getBrowser(); alert( "您使用的浏览器是" +explorer+ "浏览器" ); }; </script> </body> </html> |
采纳一下吧,让我加个学分啊
- 参与学习 人
- 提交作业 11218 份
- 解答问题 36712 个
从一个不会编程的小白到一个老司机是需要过程的,首先得入门,学习基础知识,然后才能进阶,最后再到精通,本专题是你走进前端世界的不二选择!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧