Multiple methods for js to determine whether a mobile app is installed _ javascript skills

Source: Internet
Author: User
This article mainly introduces multiple methods for js to determine whether a mobile app is installed, interested friends can refer to the examples in this article to explain a variety of methods for js to determine whether a mobile app is installed. The details are as follows:

Method 1:

I. Identify the 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

Ii. Android devices:Principle: Determine whether you know the protocol. If you know this protocol, you can directly jump to it. If you don't know it, download the app here.

Android (); if (isAndroid) {function android () {window. location. href = "openwjtr: // com. tyrbl. wjtr ";/*** open the app protocol. Some Android colleagues provide ***/window. setTimeout (function () {window. location. href = "http://www.wjtr.com/download/index.html";/*** open the app protocol, Android colleagues provide ***/}, 2000 );};

Ii. ios devices:Principle: Determine whether or not you know the protocol. If you do not know the protocol, you can directly jump to it. If you do not know it, download appios () here ();

If (isiOS) {function ios () {var ifr = document. createElement ("iframe"); ifr. src = "openwjtr: // com. tyrbl. wjtr ";/*** open the app protocol. Some 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 app address ***/}, 2000 )};}

Method 2:

Although an app can be started in Js, it cannot be determined whether the app is installed;
It takes a long time to start the app and a long js interruption time. If the app is not installed, JavaScript will be executed in an instant. Go directly to the code!
Html code:

Call

Js Code:

Function testApp (url) {var timeout, t = 1000, hasApp = true; setTimeout (function () {if (hasApp) {alert ('app installed ');} else {alert ('app not 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 );}

Method 3:

Recently, the wap version of the project has a need to first determine whether there is an APP on the mobile phone. If there is an APP, the application will not jump to the wap page until it is opened.
Wap is simply a website running on a mobile browser. No matter where the application is located, it is simply a browser. You can use JS to determine whether an application exists locally. The actual implementation method is to convert the http protocol to the local software protocol.
Paste the Code directly.
As follows:

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.