检测HTTP里面的AGENT可以识别浏览器类型,QQ浏览器的AGENT里面含有关键字QQBrowser
例如例如下面是这些AGENT就属于QQ浏览器:
1.Mozilla/5.0 (compatibleMSIE 9.0Windows NT 6.1Trident/5.0)
2.QQBrowser/9.1.4375.400
3.Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko)
4.Chrome/31.0.1650.48 Safari/537.36 QQBrowser/7.6.21433.400
5.Mozilla/4.0 (compatibleMSIE 6.0Windows NT 5.1SV1) QQBrowser/6.12.12934.201
6.Mozilla/4.0 (compatibleMSIE 6.0Windows NT 5.1SV1) QQBrowser/6.3.8908.201
检测HTTP里面的AGENT可以识别浏览器类型,QQ浏览器的AGENT里面含有关键字QQBrowser,例如例如下面是这些AGENT就属于QQ浏览器:Mozilla/5.0 (compatibleMSIE 9.0Windows NT 6.1Trident/5.0)
QQBrowser/9.1.4375.400
Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/31.0.1650.48 Safari/537.36 QQBrowser/7.6.21433.400
Mozilla/4.0 (compatibleMSIE 6.0Windows NT 5.1SV1) QQBrowser/6.12.12934.201
Mozilla/4.0 (compatibleMSIE 6.0Windows NT 5.1SV1) QQBrowser/6.3.8908.201
PHP使用变量$_SERVER['HTTP_USER_AGENT' ]可以获得浏览器AGENT字符串,例如下面的代码就可以:
<?PHP
echo $_SERVER['HTTP_USER_AGENT' ]
?>
PHP代码里面可以使用正则表达式来判断是否使用的QQ浏览器,例子代码如下:
<?php
if (preg_match('/QQBrowser/i',$_SERVER['HTTP_USER_AGENT' ])) echo '是QQ浏览器'
else echo '不是QQ浏览器'
?>
function checkBrowser(){var ua = navigator.userAgent.toLocaleLowerCase()
var browserType=null
if (ua.match(/msie/) != null || ua.match(/trident/) != null) {
browserType = "IE"
browserVersion = ua.match(/msie ([\d.]+)/) != null ? ua.match(/msie ([\d.]+)/)[1] : ua.match(/rv:([\d.]+)/)[1]
} else if (ua.match(/firefox/) != null) {
browserType = "火狐"
}else if (ua.match(/ubrowser/) != null) {
browserType = "UC"
}else if (ua.match(/opera/) != null) {
browserType = "欧朋"
} else if (ua.match(/bidubrowser/) != null) {
browserType = "百度"
}else if (ua.match(/metasr/) != null) {
browserType = "搜狗"
}else if (ua.match(/tencenttraveler/) != null || ua.match(/qqbrowse/) != null) {
browserType = "QQ"
}else if (ua.match(/maxthon/) != null) {
browserType = "遨游"
}else if (ua.match(/chrome/) != null) {
var is360 = _mime("type", "application/vnd.chromium.remoting-viewer")
function _mime(option, value) {
var mimeTypes = navigator.mimeTypes
for (var mt in mimeTypes) {
if (mimeTypes[mt][option] == value) {
return true
}
}
return false
}
if(is360){
browserType = '360'
}else{
browserType = "谷歌"
}
}else if (ua.match(/safari/) != null) {
browserType = "Safari"
}
return browserType
}
亲测有用!