When developing WeChat public accounts, a large part of it is the development of microsites. We need to know that the current browser is WeChat’s built-in browser, so how to judge?
User Agent of WeChat’s built-in browser
How to determine the WeChat built-in browser, you first need to obtain the User Agent of the WeChat built-in browser. After testing the WeChat browser on the iPhone, its User Agent is:
Mozilla/5.0 (iPhone; CPU iPhone OS 6_1_3 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Mobile/10B329 MicroMessenger/5.0.1
So by identifying the keyword MicroMessenger, you can determine whether WeChat has a built-in browser.
Judge via JavaScript
function is_weixin(){ var ua = navigator.userAgent.toLowerCase(); if(ua.match(/MicroMessenger/i)=="micromessenger") { return true; } else { return false; } }
Judge via PHP
function is_weixin(){ if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false ) { return true; } return false; }