Received a demand last week, the demand is like this: the user sweeps a two-dimensional code will produce a link, the link will send a request back, return to a apk download address, users click the download button can download this apk. Then there is a problem, after testing, found with a micro-letter sweep open Page Click download button can not download apk, after Baidu, the original is a micro-letter built-in browser shielding the download link, the back and demand side communication, the need to change if the user is using a micro-letter built-in browser open, prompts the user to change a browser to open the page, Otherwise download is not apk. So how can you tell if the user is using a micro-mail browser?
We know that JS can use window.navigator.userAgent to get information about the browser, such as: mozilla/5.0 (Windows NT 5.1) applewebkit/537.36 (khtml, like Gecko chrome/33.0.1750.154 safari/537.36, then we can also use this method to obtain information about the micro-letter built-in browser: mozilla/5.0 (iPhone; CPU iPhone os 7_1_1 like Mac os X applewebkit/537.51.2 (khtml, like Gecko) mobile/11d201 micromessenger/5.3. Based on the keyword Micromessenger to determine whether the micro-mail built-in browser. The judgment function is as follows:
Copy Code code as follows:
function Isweixin () {
var ua = Window.navigator.userAgent.toLowerCase ();
if (Ua.match (/micromessenger/i) = = ' Micromessenger ') {
return true;
}else{
return false;
}
}
Demo
Copy Code code as follows:
<! DOCTYPE html>
<meta charset= "Utf-8"/>
<title> judge whether the micro-letter built-in browser </title>
<body>
<p></p>
</body>
<script type= "Text/javascript" >
Window.onload = function () {
if (Isweixin ()) {
var p = document.getelementsbytagname (' P ');
p[0].innerhtml = window.navigator.userAgent;
}
}
function Isweixin () {
var ua = Window.navigator.userAgent.toLowerCase ();
if (Ua.match (/micromessenger/i) = = ' Micromessenger ') {
return true;
}else{
return false;
}
}
</script>
Description: You can put the above demo on the server, and then generate a two-dimensional code sweep.