This article explained the JS to determine whether the mobile end of the installation of a variety of app methods, to share with you for your reference, the specific contents are as follows
The first method:
One: Judging is the kind of equipment
var isandroid = u.indexof (' Android ') >-1 | | U.indexof (' Linux ') >-1; Android Terminal or UC browser
var Isios =!! U.match (/\ (i[^;] +;( U;)? Cpu.+mac OS x/); iOS terminal
Two: Android equipment: principle: To determine whether to recognize this agreement, the realization of the direct jump, do not know right here to download the app
Android ();
if (isandroid) {
function Android () {
window.location.href = "OPENWJTR://COM.TYRBL.WJTR";/*** Open App Protocol, An Android colleague provides ***/
window.settimeout (function () {
window.location.href = "http://www.wjtr.com/download/index.html"; /*** opened the app agreement, with an Android colleague providing ***/
},2000);
Two: iOS equipment: principle: To determine whether to recognize this agreement, the realization of the direct jump, do not know right here to download Appios ();
if (isios) {
function iOS () {
var IFR = document.createelement ("iframe");
IFR.SRC = "OPENWJTR://COM.TYRBL.WJTR"; /*** opened the app's protocol, with iOS colleagues providing ***/
Ifr.style.display = "None";
Document.body.appendChild (IFR);
Window.settimeout (function () {
document.body.removeChild (IFR);
Window.location.href = "http://www.wjtr.com/download/index.html"; /*** download App's address ***/
},2000)
}
The second method:
Although in JS can start an app, but can not determine whether the app is installed;
Start the app takes a long time, JS interrupt time is long, if not installed, JS instantaneous execution completed. Go directly to the code!
HTML code:
<a href= "Javascript:testapp (' tel:1868888888 ')" > Call </a>
JS Code:
function testApp (URL) {
var timeout, t = 1000, Hasapp = true;
settimeout (function () {
if (Hasapp) {
alert (' installed app ');
} else {
alert (' app not installed ');
}
Document.body.removeChild (IFR);
}
var t1 = Date.now ();
var IFR = document.createelement ("iframe");
Ifr.setattribute (' src ', url);
Ifr.setattribute (' style ', ' display:none ');
Document.body.appendChild (IFR);
Timeout = settimeout (function () {
var t2 = Date.now ();
if (!t1 | | t2-t1 < T +) {
Hasapp = false;}
, T);
}
The third method:
Recently in the WAP version of the project, there is a need to determine whether there is a mobile phone on our app application, if some words open application, did not jump to the WAP page.
WAP is simply a Web site running on a mobile-side browser. No matter where the application, in short is the browser, you can use JS to determine whether there is a local application, the implementation of the way is the HTTP protocol to the local software protocol.
Just stick to the code.
As follows:
<script language= "JavaScript" > if (navigator.userAgent.match );?
/i) {var loaddatetime = new Date ();
Window.settimeout (function () {var timeoutdatetime = new Date ();
if (Timeoutdatetime-loaddatetime < 5000) {window.location = "page URL to jump";
else {window.close ();
}, 25);
window.location = "Apps custom URL schemes";
else if (Navigator.userAgent.match (/android/i)) {var state = null;
try {state = window.open ("Apps Custom URL schemes", ' _blank ');
catch (e) {} if (state) {window.close ();
else {window.location = "page URL to jump"; } {</script>
Apps custom URL Schemes what is it?
is actually a protocol URL to your app, and your iOS colleague or Android colleague will set a URL Scheme when writing the program.
For example, set:
URL Scheme:app
The application can then be invoked by the other program via urlstring = app://.
You can also pass parameters, such as:
app://reaction/?uid=1
principle:within 500ms, this machine has the application to parse this protocol and open the program, call the application, if the machine does not have an application to resolve the protocol or 500MS does not open this program, Then execute settimeout inside function, is to jump to the page you want to jump.
The above is JS to determine whether the mobile end of the installation of a variety of app methods, I hope to help you learn.