How to judge WeChat's built-in browser (implemented through UserAgent) _ javascript skills

Source: Internet
Author: User
When developing a public account, you need to know that the current browser is a built-in browser. How can this problem be determined? This is only through the browser's UserAgent to determine the development of public accounts, a large part of which is the development of micro-sites, we need to know that the current browser is a built-in browser, so how to judge?

Built-in browser User Agent

To determine the built-in browser, you first need to obtain the User Agent of the built-in browser. After detection by the 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 identify the keyword MicroMessenger to determine whether the browser is built in.

JavaScript-based judgment

Function is_weixin () {var ua = navigator. userAgent. toLowerCase (); if (ua. match (/MicroMessenger/I) = "micromessenger") {return true;} else {return false ;}}

PHP-based judgment

Function is_weixin () {if (strpos ($ _ SERVER ['HTTP _ USER_AGENT '], 'micromessenger ')! = False) {return true;} return false ;}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.