我们可以使用JavaScript中的userAgent函数,来判断网站是否为QQ内置浏览器访问的方法,就可以轻松的防止域名被QQ微信红名提示。
相比于写程序代码的方法,JS这种方法更简单,只需一段JS代码即可完成。
判断是否为微信访问
let is_weixin = (function () { let ua = navigator.userAgent.toLowerCase(); if (ua.match(/MicroMessenger/i) == 'micromessenger') { return true; } else { return false; } })();
判断是否为QQ访问
let is_qq = (function () { let sUserAgent = navigator.userAgent.toLowerCase(); if (sUserAgent.match(/QQ/i) == 'qq') { return true } else { return false } })();
判断是否为QQ微信访问
var ua = navigator.userAgent.toLowerCase(); if(ua.match(/MicroMessenger/i)=="micromessenger") { //return "weixin"; alert("微信") } else if (ua.match(/QQ/i) == "qq") { //return "QQ"; alert("QQ") }else { return false; alert("不是微信浏览器或手机qq浏览器"); }