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