判断qq浏览器和uc浏览器?

时间:2023-03-09 15:57:02
判断qq浏览器和uc浏览器?

判断在iphone手机上打开的是uc浏览器还是qq浏览器

<html lang="en">
<head>
<meta charset="utf-8">
<script src="./jquery-2.1.4.min.js"></script>
</head>
<!-- navigator.userAgent.indexOf(' QQ') > -1 -->
<body>
<div style="height: 200px;width: 200px;background-color: red" id="test"></div>
</body>
</html>
<script> if(/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)){
$("#test").css("background-color",'blue');
if(navigator.userAgent.indexOf('UCBrowser') > -1){
$("#test").css("background-color",'black');
}else if(new RegExp('MQQBrowser').test(navigator.userAgent)){
$("#test").css("background-color",'yellow');
} }
</script> 

1.判断是不是iphone手机?

/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)

是true就执行下一步

2.判断uc浏览器?

navigator.userAgent.indexOf('UCBrowser') > -1

3.判断qq浏览器

new RegExp('MQQBrowser').test(navigator.userAgent)

其实你只要打印一个alert(navigator.userAgent),在那个浏览器打开就好了,就知道有没有错~~~~~

这是我用一个起作用就变色的来试