When developing WeChat public accounts, a large part of it is the development of micro-sites. We need to know that the current browser is a built-in browser for WeChat. So how to judge?
User Agent with built-in browser for WeChat
To determine the built-in browser of WeChat, you first need to obtain the User Agent of the built-in browser of WeChat. After detection by WeChat's browser on 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, we can determine whether the browser is built-in to WeChat.
Judgement through JavaScript
function is_weixin(){var ua = navigator.userAgent.toLowerCase();if(ua.match(/MicroMessenger/i)=="micromessenger") {return true;} else {return false;}}Judge by PHP
function is_weixin(){ if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false ) {return true;} return false;}The above is what the editor introduces to you to determine the browser type used when a user requests is determined through JS and PHP. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!