JS to determine whether the mobile side installs an app's many ways

Source: Internet
Author: User

The first method:

One : Judging is the kind of device

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 device: principle: Judge whether to know this agreement, know the direct jump, do not know to download the app here

Android ();

if (isandroid) {

Function Android () {

Window.location.href = "OPENWJTR://COM.TYRBL.WJTR"; /*** opens the app protocol, with Android colleagues providing ***/

Window.settimeout (function () {

Window.location.href = "http://www.wjtr.com/download/index.html"; /*** opens the app protocol, with Android colleagues providing ***/

},2000);

};

Two:iOS device: Principle: Judge whether to know this agreement, know directly jump, do not know here download Appios ();

if (Isios) {

function iOS () {

var IFR = document.createelement ("iframe");

IFR.SRC = "OPENWJTR://COM.TYRBL.WJTR"; /*** Open the app protocol and have iOS colleagues provide ***/

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 the app's address ***/

},2000)

};

}

The second method:

although in JS can start an app, but not to 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 = $, Hasapp = true;

SetTimeout (function () {

if (Hasapp) {

Alert (' Install app ');

} else {

Alert (' No app installed ');

}

Document.body.removeChild (IFR);

}, 2000)

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 + 100) {

Hasapp = false;

}

}, T);

}

The third method:

recently in the WAP version of the project, there is a need to determine whether the mobile phone has our app, if some words open the application, not only jump to the WAP page.
WAP is simply a website that runs on a mobile browser. Regardless of where the application is, in short, the browser chant, you can use JS to determine whether there is an application, the implementation of the actual way is to convert the HTTP protocol to the local software protocol.
Or just stick to the code.
As follows:

<script language= "JavaScript" >

if (Navigator.userAgent.match (/(Iphone|ipod|ipad);? /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>

What is the apps custom URL schemes?
It 's actually you and An app protocol URL that your iOS colleague or Android colleague will set up a URL Scheme when writing a program.
For example, set:
URL Scheme:app
and then the other programs can go through URLString = app://calls the app.
You can also pass parameters, such as:
App://reaction/?uid=1
principle:within 500ms, this machine has the application to resolve this protocol and open the program, call the application, if the native no application can resolve the protocol, or 500MS does not open the program, then execute settimeout inside the function, is to jump to the page you want to jump to.

The above is the JS to determine whether the mobile terminal installation of a variety of methods, I hope that everyone's learning has helped.

JS to determine whether the mobile side installs an app's many ways

Related Article

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.