js 判断手机上是否存在某App 如果存在就拉起App 否则 跳转至下载链接

判断手机上是否存在某App 如果存在就拉起App 否则 跳转至下载链接 (agreement)为App给web的一个协议,为APP那边提供原理:按拉起时间判断&#xff0

// 判断手机上是否存在某App 如果存在就拉起App 否则 跳转至下载链接
// (agreement)为App给web的一个协议,为APP那边提供
//原理:按拉起时间判断,手机上是否存在该APP
function testApp(agreement,url) {   
    var t = 1000, hasApp = true;   
    setTimeout(function () {     
        if (hasApp) {       
            return false;     
        } else {       
            window.location.href = url; //如果手机上不存在该应用,则跳转至该链接。  
        }     
        document.body.removeChild(ifr);   
    }, 2000);     
    var t1 = Date.now();   
    var ifr = document.createElement("iframe");   
    ifr.setAttribute('src', agreement);   
    ifr.setAttribute('style', 'display:none');   
    document.body.appendChild(ifr);   
    setTimeout(function () {      
        var t2 = Date.now();      
        if (!t1 || t2 - t1 < t + 100) {        
            hasApp = false;      
        }   
    }, t); 
};

发布者:admin,转转请注明出处:http://www.yc00.com/web/1754592855a5179345.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信