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;