We first get the browser UA:
1 var ua = navigator.useragent;
1 if (Ua.indexof ("Micromessenger") >-1) {2 alert ("browser"); 3
1 if (Ua.indexof ("iphone") >-1) {2 alert ("iphone"); 3 }
Other browsers and mobile browsers have their own UA, we can find it in the middle of a keyword to judge it, do not list down, on the internet can be checked, here only to explain the method of determination.
We use the UA to determine which mobile device a visitor uses to make a request for a page, which can be done using urlschema, location.href = "appiphone://", which can drop the corresponding app in the iphone. The premise is that this appiphone is registered in the app we've developed, so it can evoke the client.
Then we can determine whether the app is activated by judging the visibility status of the browser page, or if it is not activated, we can continue to work on the page, or let the program visit the store to download the app.
1 if (Ua.indexof ("IPhone") >-1) {2 location.href = "appiphone://"; 3 Window.settimeout (function() {4 iffalse) { 5 Location.href = "http://itunes.apple.com/cn/app/"; 6 }7 }, (); 8
JavaScript ua and Urlschema