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