如何识别是否使用360浏览器
当前360浏览器使用chorme浏览器内核,其useragent的查询结果是:
Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1
明显在useragent中无法找到360的任何痕迹。相应comodo使用firefox内核的ice dragon是:
Mozilla/5.0 (Windows NT 6.2; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0 IceDragon/25.0.0.1
网上搜索了一下,找到识别360浏览器的代码
try {
if (window.external && window.external.twGetRunPath) {
var r = external.twGetRunPath();
if (r && (r.toLowerCase().indexOf("360se") > -1 )) {
ret = true;
}
}
} catch (ign) {
ret = false;
}
这个代码没有使用useragent,使用window.external.twGetRunPath来识别浏览器运行目录,如果运行目录中包含360se字符,则表明所使用为360浏览器。
例如在windows 8.1下,360浏览器默认安装目录为:
C:\Users***\AppData\Roaming\360se6\Application\360se.exe
<script language="javascript" type="text/javascript">
var g_bRunIn360se = false;
var g_strSecurityId = null;
try{
g_strSecurityId = external.twGetSecurityID(window);
g_bRunIn360se = true;
}
catch(e){
if (g_bRunIn360se==false){g_bRunIn360se=navigator.userAgent.toLowerCase().indexOf("360chrome");}
}
if (g_bRunIn360se==true){
alert("系统检测出来你使用了360流氓浏览器,请先卸载或改用IE、Chrome或firefox 等再行访问本站,谢谢合作!");
document.execCommand("stop");
}
</script>
PHP版代码如下:
<?php
$useragent = $_SERVER['HTTP_USER_AGENT'];
if(strstr($useragent,"360")) {die("系统检测出来你使用了360流氓浏览器,请先卸载或改用IE、Chrome或firefox 等再行访问本站,谢谢合作!");} ?>