


JS implements clicking on the web page to determine whether to install the app and open it, otherwise jump to the app store
There are often scenarios where the APP we develop needs to be promoted, such as a large banner picture or a QR code at the top of the page. But often we directly add a download link (from the App Store) to the promotional image. So let’s simulate the user’s operation steps:
1. The user visits the promotion page for the first time
a. Click Banner and enter the corresponding APP download page in the APP Store
b. The APP download page prompts: 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. The user uses the APP normally
2. The user visits the promotion page for the second time
a. Click Banner to enter Go to the corresponding APP download page in the APP Store
b. The APP download page prompts: Open; the user directly clicks to open
c. The user uses the APP normally
3. The user’s third, fourth,..., For the Nth visit, the operation steps are the same as 2
It can be seen that whether it is clicking the Banner or scanning the QR code, the experience is very bad for users who have already installed the APP.
A better experience is: after clicking the Banner (or scanning the QR code), the program will determine whether the App has been installed on the current system. If not, it will automatically jump to the App Store download page; otherwise, open the App directly.
On iOS, to add a large Banner for an APP, you only need to add a tag within the
tag. The format is as follows:<meta name='apple-itunes-app' content='app-id=你的APP-ID'>
For example, add a Baidu Tieba Native APP Banner, 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, you can use the following code to achieve it. Prerequisite: You must know the opening protocol corresponding to your APP, such as Tieba APP, the protocol is: com.baidu.tieba://, WeChat: weixin://, and so on. . .
<!-- a标签的链接,设置为对应的下载链接;点击打开的动作,在click事件中注册 --> <a href="https://itunes.apple.com/cn/app/id477927812" id="openApp">贴吧客户端</a> <script type="text/javascript"> document.getElementById('openApp').onclick = function(e){ // 通过iframe的方式试图打开APP,如果能正常打开,会直接切换到APP,并自动阻止a标签的默认行为 // 否则打开a标签的href链接 var ifr = document.createElement('iframe'); ifr.src = 'com.baidu.tieba://'; ifr.style.display = 'none'; document.body.appendChild(ifr); window.setTimeout(function(){ document.body.removeChild(ifr); },3000) }; </script>
Of course, if you design it as a QR code, you can use the following code:
<!-- a标签的链接,设置为对应的下载链接;点击打开的动作,在click事件中注册 --> <a href="https://itunes.apple.com/cn/app/id477927812" id="openApp" style="display: none">贴吧客户端</a> <script type="text/javascript"> document.getElementById('openApp').onclick = function(e){ // 通过iframe的方式试图打开APP,如果能正常打开,会直接切换到APP,并自动阻止a标签的默认行为 // 否则打开a标签的href链接 var ifr = document.createElement('iframe'); ifr.src = 'com.baidu.tieba://'; ifr.style.display = 'none'; document.body.appendChild(ifr); window.setTimeout(function(){ document.body.removeChild(ifr); },3000) }; document.getElementById('openApp').click();
Which one to use depends on your actual scenario!
When we browse the web, you will see a prompt box "Open APP" or "Download APP" floating below the web page. If your phone has already installed this APP, then the web page will prompt "Open APP" ”, if it is not installed, it will prompt “download APP”. How is this implemented from a technical perspective? Let me share this technology with you. When the company was working on a project for the International Cartoon and Animation Festival last year, the customer mentioned this requirement. When clicking on the web page company, open the APP directly (if it is already installed). If it has not been installed, open it directly. APP page
Now I will share the source code of this piece
if(navigator.userAgent.match(/android/i)) { // 通过iframe的方式试图打开APP,如果能正常打开,会直接切换到APP,并自动阻止a标签的默认行为 // 否则打开a标签的href链接 var isInstalled; //下面是安卓端APP接口调用的地址,自己根据情况去修改 var ifrSrc = 'cartooncomicsshowtwo://platformapi/startApp? type=0&id=${com.id}&phone_num=${com.phone_num}'; var ifr = document.createElement('iframe'); ifr.src = ifrSrc; ifr.style.display = 'none'; ifr.onload = function() { // alert('Is installed.'); isInstalled = true; alert(isInstalled); document.getElementById('openApp0').click();}; ifr.onerror = function() { // alert('May be not installed.'); isInstalled = false; alert(isInstalled); } document.body.appendChild(ifr); setTimeout(function() { document.body.removeChild(ifr); },1000); } //ios判断 if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) { //Animation://com.yz.animation var isInstalled; //var gz = '{"comName":"${com.short_name}","comID":"${com.id}","comPhoneNum":"${com.phone_num}","type":"0"}'; //var jsongz =JSON.parse(gz); //下面是IOS调用的地址,自己根据情况去修改 var ifrSrc = 'Animation://?comName=${com.short_name}&comID=${com.id}&comPhoneNum=${com.phone_num}&type=0';var ifr = document.createElement('iframe'); ifr.src = ifrSrc; ifr.style.display = 'none'; ifr.onload = function() { // alert('Is installed.'); isInstalled = true; alert(isInstalled); document.getElementById('openApp1').click();}; ifr.onerror = function() { // alert('May be not installed.'); isInstalled = false; alert(isInstalled); } document.body.appendChild(ifr); setTimeout(function() { document.body.removeChild(ifr); },1000); } }
Everyone needs to pay attention to two issues during the process:
1. The interface address must be written correctly. You can check the schema protocol , called through this protocol
2. When using Android, if you use WeChat scan or QQ browser to scan the code
There will be a problem when using the above protocol, which is that you must use APK to list it on Tencent Go to the app market

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Face detection and recognition technology is already a relatively mature and widely used technology. Currently, the most widely used Internet application language is JS. Implementing face detection and recognition on the Web front-end has advantages and disadvantages compared to back-end face recognition. Advantages include reducing network interaction and real-time recognition, which greatly shortens user waiting time and improves user experience; disadvantages include: being limited by model size, the accuracy is also limited. How to use js to implement face detection on the web? In order to implement face recognition on the Web, you need to be familiar with related programming languages and technologies, such as JavaScript, HTML, CSS, WebRTC, etc. At the same time, you also need to master relevant computer vision and artificial intelligence technologies. It is worth noting that due to the design of the Web side

How to use JS and Baidu Map to implement map pan function Baidu Map is a widely used map service platform, which is often used in web development to display geographical information, positioning and other functions. This article will introduce how to use JS and Baidu Map API to implement the map pan function, and provide specific code examples. 1. Preparation Before using Baidu Map API, you first need to apply for a developer account on Baidu Map Open Platform (http://lbsyun.baidu.com/) and create an application. Creation completed

Essential tools for stock analysis: Learn the steps to draw candle charts in PHP and JS. Specific code examples are required. With the rapid development of the Internet and technology, stock trading has become one of the important ways for many investors. Stock analysis is an important part of investor decision-making, and candle charts are widely used in technical analysis. Learning how to draw candle charts using PHP and JS will provide investors with more intuitive information to help them make better decisions. A candlestick chart is a technical chart that displays stock prices in the form of candlesticks. It shows the stock price

How to use PHP and JS to create a stock candle chart. A stock candle chart is a common technical analysis graphic in the stock market. It helps investors understand stocks more intuitively by drawing data such as the opening price, closing price, highest price and lowest price of the stock. price fluctuations. This article will teach you how to create stock candle charts using PHP and JS, with specific code examples. 1. Preparation Before starting, we need to prepare the following environment: 1. A server running PHP 2. A browser that supports HTML5 and Canvas 3

Overview of how to use JS and Baidu Maps to implement map click event processing: In web development, it is often necessary to use map functions to display geographical location and geographical information. Click event processing on the map is a commonly used and important part of the map function. This article will introduce how to use JS and Baidu Map API to implement the click event processing function of the map, and give specific code examples. Steps: Import the API file of Baidu Map. First, import the file of Baidu Map API in the HTML file. This can be achieved through the following code:

How to use JS and Baidu Maps to implement the map heat map function Introduction: With the rapid development of the Internet and mobile devices, maps have become a common application scenario. As a visual display method, heat maps can help us understand the distribution of data more intuitively. This article will introduce how to use JS and Baidu Map API to implement the map heat map function, and provide specific code examples. Preparation work: Before starting, you need to prepare the following items: a Baidu developer account, create an application, and obtain the corresponding AP

With the rapid development of Internet finance, stock investment has become the choice of more and more people. In stock trading, candle charts are a commonly used technical analysis method. It can show the changing trend of stock prices and help investors make more accurate decisions. This article will introduce the development skills of PHP and JS, lead readers to understand how to draw stock candle charts, and provide specific code examples. 1. Understanding Stock Candle Charts Before introducing how to draw stock candle charts, we first need to understand what a candle chart is. Candlestick charts were developed by the Japanese

The relationship between js and vue: 1. JS as the cornerstone of Web development; 2. The rise of Vue.js as a front-end framework; 3. The complementary relationship between JS and Vue; 4. The practical application of JS and Vue.
