How does js determine whether a user uses WeChat browser _ javascript skills?

Source: Internet
Author: User
The built-in browser shields the download link. If the user opens the page with a built-in browser, the user is prompted to open the page with another browser. How can I determine whether the user is using a browser? I received a request last week, the requirement is as follows: a link is generated when you scan the QR code. The link sends a request to the backend and returns an apk. You can click the Download button to download this apk. Then there was a problem. After testing, we found that the apk could not be downloaded by clicking the Download button on the page opened by a scan. After Baidu, the download link was originally blocked by the built-in browser, communicate with the demand side later. If the user opens the page with a built-in browser, the user is prompted to open the page with another browser. Otherwise, the apk cannot be downloaded. How can we determine whether a user uses a browser?

We know that js can be implemented through window. navigator. userAgent to obtain 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, we can also use this method to obtain information about the 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. Determine whether the browser is built based on the keyword MicroMessenger. The judgment function is as follows:

The Code is as follows:


Function isWeiXin (){
Var ua = window. navigator. userAgent. toLowerCase ();
If (ua. match (/MicroMessenger/I) = 'micromessenger '){
Return true;
} Else {
Return false;
}
}


Demo:

The Code is as follows:






Determine if it is a built-in browser


If you open it in a browser, you can see the following text




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.