JS how to determine whether the user is using a micro-letter browser _javascript Skills

Source: Internet
Author: User
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.
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.