Judging whether a user installs an app in a mobile browser

  node.js, question

There is a “Open Now” button on the current page. If the user has already installed the app, the corresponding app will be called to open, otherwise jump to the download page.

Scheme of known app

Method 1 found online:

$(document).ready(function () {
 var log = function (msg) {
 $ ('body'). before ('< divclass = "log" >' plus msg plus' < /div >');
 };
 var timeout, t = 1000, hasApp = true;
 
 setTimeout(function () {
 if (hasApp) {
 Log ('app installed');
 } else {
 Log ('app not installed');
 bracket
 }, 2000);
 function testApp() {
 var t1 = Date.now();
 var ifr = $('<iframe id="ifr"></iframe>');
 ifr.attr('src', 'diaodiao://');
 $('body').append(ifr);
 //After insertion, execute the try_to_open_app method over 1000 ms.
 timeout = setTimeout(function () {
 try_to_open_app(t1);
 }, t);
 bracket
 function try_to_open_app(t1) {
 var t2 = Date.now();
 if (!  T1 || t2-t1 < t plus 200)
 hasApp = false;
 bracket
 bracket
 testApp();
 });

Method 1 does not work; log typed on the page will always be “app not installed.”

Method 2 for online search:

window.onload = function(){
    function isInstalled(){
        var originHref = location.href;
        var url = originHref.substring(originHref.indexOf('//')加2);
        var schemeUrl = "diaodiao://"加url;
        window.location=schemeUrl;//打开某手机上的某个app应用
        setTimeout(function(){
            window.location="http://a.app.qq.com/o/simple.jsp?pkgname=com.diaox2.android&ckey=CK1308661595241";//如果超时就跳转到app下载页
        },20000);
    }
    var downlink = document.querySelector('.downlink');
    downlink.addEventListener('click',function(){
        isInstalled();
    },false)
}

The problem with this method is that,window.location=schemeUrl;After this code is executed, safari pops up a dialog box asking whether to use the corresponding app to open it, and then jumps to the download link (isn’t it timed? I don’t know why the timer doesn’t work. )

—————–new——————-

The above two methods must have their applicable periods. These are solutions at least more than one year ago.
 With the update of IOS/Android system and browser, it is no longer applicable.  .
 
 
 Using iframe to call app, I can call it in safari under IOS8.3, but safari under 9.2.1 is not.
 
 The test also failed under Android5.0.1, but it can only be called up under Android Chrome.  .

I met a buddy who looked like my question, but he didn’t seem to have a good answer.
The problem of opening app through scheme in browser under ios9.
—————–new——————-

Finally resolved (although not so elegant, not covering all browsers or webview), wrote a document:
About judging whether to install app in browser

Meanwhile, thank you, not stint!

As it seems, ios usually uses iframe to open your scheme address. Location.href is usually used under Android. . .
However, the actual situation seems to be much more complicated than this. . . .
The landlord can refer to this:http://js.40017.cn/touch/hb/p/openApp.js