How to judge the built-in browser of WeChat

 Wolf
2016-01-13 / 0 Comments / 2337 Reading / Checking whether to include

Today, we are making a mobile phone adaptation version for a project. It was originally a PC page, but for mobile phones, it will automatically jump to the corresponding mobile phone page, so we started the test. We found that the first one to open the PC by default after WeChat scanned the QR code, so we started to judge what the browser built in WeChat is.

 How to judge the built-in browser of WeChat

Under iPhone, the UserAgent returned by WeChat is:

Mozilla/5.0 (iPhone; CPU iPhone OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9B176 MicroMessenger/4.3.2

Under Android, the returned UserAgent is:

Mozilla/5.0 (Linux; U; Android 2.3.6; zh-cn; GT-S5660 Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 MicroMessenger/4.5.255

After careful observation, it is found that all of them are equipped with MicroMessenger, which is used to judge.

Use JavaScript to judge how the code:

function is_weixin(){

var ua = navigator.userAgent.toLowerCase();

if(ua.match(/MicroMessenger/i)=="micromessenger"){

 return true;

}else{

 return false;

}

}

Use PHP code to judge. The code is as follows:

function is_weixin(){ 

if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false ) {

  return true;

  return false;

}


zero

Comments (0)

cancel