网页推荐下载App,如果本地已安装则直接打开本地App

function open_or_download_app() {  
    if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {  
        // 判断useragent,当前设备为ios设备  
        var loadDateTime = new Date(); // 设置时间阈值,在规定时间里面没有打开对应App的话,直接去App store进行下载。  
        window.setTimeout(function() {  
            var timeOutDateTime = new Date();  
            if (timeOutDateTime - loadDateTime < 2000) {  
                window.location = "https://itunes.apple.com/cn/app/hu-lu/id627370076?mt=8";  
            } else {  
                window.close();  
            }  
        },  50);  
        window.location = "XXX://"; // iOS端URL Schema  
    } else if (navigator.userAgent.match(/android/i)) {  
        // 判断useragent,当前设备为android设备  
        window.location = "XXX://"; // Android端URL Schema   
    }   
}

猜你喜欢

转载自sking777.iteye.com/blog/2004813