Home > Web Front-end > JS Tutorial > body text

How to determine WeChat's built-in browser (implemented through User Agent)_javascript skills

WBOY
Release: 2016-05-16 16:38:11
Original
1440 people have browsed it

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;
}
}
Copy after login

Judge via PHP

function is_weixin(){ 
if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false ) {
return true;
} 
return false;
}
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!