JavaScript to judge micro-letter Browser instance Code _javascript tips

Source: Internet
Author: User

First of all, I want to tell you my project requirements: Users sweep a two-dimensional code will produce a link, the link will send a request back 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:

function Isweixin () {
var ua = Window.navigator.userAgent.toLowerCase ();
if (Ua.match (/micromessenger/i) = = ' Micromessenger ') {return
true;
} else{return
false;
}

Demo

<! DOCTYPE html>
 
 

Description: You can put the above demo on the server, and then generate a two-dimensional code sweep.

The above is a small set to introduce JavaScript to judge the micro-letter browser Instance code knowledge, hope to help everyone, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.