JavaScript determines whether it is a _javascript browser technique

Source: Internet
Author: User

First of all, the principle of implementation

Depending on whether there is a keyword micromessengerin UA, there are some words in the micro-mail built-in browser

The implementation code looks like this:

Determine whether the micro-mail login
function isweixin () {
var ua = Window.navigator.userAgent.toLowerCase ();
Console.log (UA);//mozilla/5.0 (iphone; CPU iphone OS 9_1 like Mac OS X) applewebkit/601.1.46 (khtml, like Gecko) Version/9. 0 mobile/13b143 safari/601.1
if (ua.match (/micromessenger/i) = = ' Micromessenger ') {return
true;
} else { return
false;
}
}
if (Isweixin ()) {
Console.log ("is from a micro-trust built-in browser")
}else{
console.log ("Not from a micro-trust built-in browser")
}

Micro-faith Browser ua Chestnuts

Under the iphone:

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:

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

New simulator, replace UA as shown:

Using Chrome's IPHONE5 simulation test


Ps:js to determine whether to open in a micro-mail browser

With JS to judge, after the search data finally realized the effect, directly on the code

function Is_weixn () { 
var ua = Navigator.userAgent.toLowerCase (); 
if (Ua.match (/micromessenger/i) = = "Micromessenger") {return 
true; 
} else {return 
false; 
} 

Through the test completely through, whether it is Android or Iphone,ipad can, of course, we in addition to using JS to judge, in other languages to judge is simpler, such as PHP

function Is_weixin () { 
if (Strpos ($_server[' http_user_agent '], ' Micromessenger ')!== false) {return 
true;< c16/>} return 
false; 

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.