SoFunction
Updated on 2025-03-01

JS implements clicking on the web page to determine whether the app is installed and opened, otherwise jump to the app store

There are often such scenarios where the APP we developed needs to be promoted, such as a large banner image or a QR code at the top of the page. But often we directly add a download link to the promotional image (in the App Store). So let's simulate the user's operation steps:

1. The first time the user visits the promotional page

a. Click Banner to enter the corresponding APP download page in the APP Store

b. The prompts in the APP download page: Install; the user clicks to install

c. After the installation is completed, the APP download page prompts: Open; the user continues to click to open

d. Users use APP normally

2. The second time the user visits the promotional page

a. Click Banner to enter the corresponding APP download page in the APP Store

b. The APP download page prompts: Open; the user directly clicks to open

c. Users use APP normally

3. The third, fourth,..., Nth visit, the operation steps are the same as 2

Can see, no matter if it is a clickBannerstillScan the QR codeThis experience is very bad for users who have already installed the APP.

A better experience is:After clicking Banner (or scanning the QR code), the program determines whether the App is installed in the current system. If it is not installed, it will automatically jump to the App Store download page; otherwise, open the App directly.

On iOS, to add a large banner of an APP, you only need to add a <meta> tag to the <head> tag, the format is like:

&lt;meta name='apple-itunes-app' content='app-id=yourAPP-ID'&gt;

For example, add a Baidu Tieba Native APP big banner and use the following code:

<meta name='apple-itunes-app' content='app-id=477927812'>

As for whether it can be opened directly after clicking the link, it can be achieved through the following code. Prerequisites: You have to know the corresponding opening protocol of your APP, such as Tieba APP, the protocol is:://, WeChat: weixin://, and so on. . .

&lt;!-- aTag link,Set as the corresponding download link;Click to open action,existclickRegister in the event --&gt; 
&lt;a href="/cn/app/id477927812" &gt;Tieba Client&lt;/a&gt; 
&lt;script type="text/javascript"&gt; 
('openApp').onclick = function(e){ 
// Try to open the APP through an iframe. If it can be opened normally, it will directly switch to the APP and automatically block the default behavior of the a tag.// Otherwise, open the href link of the a tagvar ifr = ('iframe'); 
 = '://'; 
 = 'none'; 
(ifr); 
(function(){ 
(ifr); 
},3000) 
}; 
&lt;/script&gt;

Of course, if you are designing it as a QR code, you can use the following code:

&lt;!-- aTag link,Set as the corresponding download link;Click to open action,existclickRegister in the event --&gt; 
&lt;a href="/cn/app/id477927812"  style="display: none"&gt;Tieba Client&lt;/a&gt; 
&lt;script type="text/javascript"&gt; 
('openApp').onclick = function(e){ 
// Try to open the APP through an iframe. If it can be opened normally, it will directly switch to the APP and automatically block the default behavior of the a tag.// Otherwise, open the href link of the a tagvar ifr = ('iframe'); 
 = '://'; 
 = 'none'; 
(ifr); 
(function(){ 
(ifr); 
},3000) 
}; 
('openApp').click();

Which one to use depends on your actual scenario!

When we browse the web page, you will see a prompt box "Open APP" or "Download APP" floating below a web page. If your phone has installed this APP, the web page will prompt "Open APP". If it is not installed, it will prompt "Download APP" from a technical perspective. How is this implemented? Next, I will share this technology with you. When the company was working on a project for the International Animation Festival last year, the customer mentioned this requirement. When clicking on the web company, open the APP directly (if it has been installed). If it has not been installed, open the APP page directly.

I'll share the source code of this section below

if((/android/i)) {
// Try to open the APP through an iframe. If it can be opened normally, it will directly switch to the APP and automatically block the default behavior of the a tag.// Otherwise, open the href link of the a tagvar isInstalled;
//The following is the address of the Android APP interface call, and you can modify it according to the situationvar ifrSrc = 'cartooncomicsshowtwo://platformapi/startApp? type=0&amp;id=${}&amp;phone_num=${com.phone_num}';
var ifr = ('iframe');
 = ifrSrc;
 = 'none';
 = function() {
// alert('Is installed.');
isInstalled = true;
alert(isInstalled);
('openApp0').click();};
 = function() {
// alert('May be not installed.');
isInstalled = false;
alert(isInstalled);
}
(ifr);
setTimeout(function() {
(ifr);
},1000);
}
//ios judgmentif((/(iPhone|iPod|iPad);?/i))
if((/(iPhone|iPod|iPad);?/i)) {
//Animation://
var isInstalled;
//var gz = '{"comName":"${com.short_name}","comID":"${}","comPhoneNum":"${com.phone_num}","type":"0"}';
//var jsongz =(gz);
//The following is the address of the IOS call, and you can modify it according to the situationvar ifrSrc = 'Animation://?comName=${com.short_name}&amp;comID=${}&amp;comPhoneNum=${com.phone_num}&amp;type=0';var ifr = ('iframe');
 = ifrSrc;
 = 'none';
 = function() {
// alert('Is installed.');
isInstalled = true;
alert(isInstalled);
('openApp1').click();};
 = function() {
// alert('May be not installed.');
isInstalled = false;
alert(isInstalled);
}
(ifr);
setTimeout(function() {
(ifr);
},1000);
}
}

There are two issues that everyone needs to pay attention to during the process:

1. The interface address must be written correctly. You can check the schema protocol and call it through this protocol.

2. When using Android, if you use WeChat to scan or QQ browser to scan the code function

If you use the above protocol, you will have a problem, that is, you must use APK to list it on Tencent application market

The above is the JS implementation introduced by the editor to you by clicking on the web page to determine whether to install the app and open it. Otherwise, it will jump to the app store. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support for my website!