I have been doing a lot of HTML5 projects recently, and many pages will be shared through SNS such as WeChat and Weibo. Provide downloads of the company's APP on the sharing page. However, in many browsers of applications, clicking on the download link cannot download the application. So for these browsers, we need to give users a prompt to open the sharing page from safari or the browser provided by the system. You can use js to determine which browser the current page is opened in.
The following is a sample code. The comments show how to judge whether it is opened in the WeChat browser, whether it is opened in the QQ space browser, and whether it is opened in the Sina Weibo through JS. Of course, it can be done more thoroughly, and in addition, it is more detailed to determine whether it is opened on a mobile device or a browser on a PC. It can be determined whether it is opened on a browser on an Android system or an IOS system.
if (browser.versions.mobile) {//Determine whether the mobile device is on. browser code is below var ua = navigator.userAgent.toLowerCase();//Get the object used for judgment if (ua.match(/MicroMessenger/i) == "micromessenger") { //Open in WeChat} if (ua.match(/WeiBo/i) == "weibo") { //Open in Sina Weibo client} if (ua.match(/QQ/i) == "qq") { //Open in QQ space} if (browser.versions.ios) { //Open in IOS browser} if (browser.versions.android){ //Open in Android browser}} else { //Otherwise, it will be opened by PC browser}Then attach the browser code, and you can judge many browsers through the following methods. Including judging IE browser, Opera browser, Safari browser, Google browser, Firefox browser, etc.
var browser = { versions: function () { var u = navigator.userAgent, app = navigator.appVersion; return { //Mobile terminal browser version information trident: u.indexOf('Trident') > -1, //IE kernel presto: u.indexOf('Presto') > -1, //opera kernel webKit: u.indexOf('AppleWebKit') > -1, //Apple and Google kernel gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //Firefox kernel mobile: !!u.match(/AppleWebKit.*Mobile.*/), //Is it a mobile terminal ios: !!u.match(//(i[^;]+;( U;)? CPU.+Mac OS X/), //ios terminal android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //Android terminal or uc browser iPhone: u.indexOf('iPhone') > -1, //Is it an iPhone or QQHD browser iPad: u.indexOf('iPad') > -1, //Is it an iPad webApp: u.indexOf('Safari') == -1 //Whether the web should be a program, no header and bottom}; }(), language: (navigator.browserLanguage || navigator.language).toLowerCase()}The above simple example (recommended) of JS to determine whether it is opened in the WeChat browser is the entire content shared by the editor. I hope it can give you a reference and I hope you can support Wulin.com more.