Js判定移动端是否安装app

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="initial-scale=1.0,user-scalable=no">
    <title>Js判定移动端是否安装app,若已安装,则打开,未安装则跳转到下载页面</title>
    <meta name='apple-itunes-app' content='app-id=1221201728'>
</head>
<body>
    <a href="javascript:;" id="openApp">点击打开安装app</a>
</body>
</html>
<script type="text/javascript">
    document.getElementById('openApp').onclick = function(e){
        
        if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i))
           {
            window.location.href = "com.baidu.tieba://";//ios app协议(如:com.baidu.tieba://)
            window.setTimeout(function() {
                window.location.href = "https://itunes.apple.com/cn/app/id477927812"; //跳转到App store
            }, 2000)
           }
        if(navigator.userAgent.match(/android/i))
        {
            window.location.href = "com.baidu.tieba://app";//android app协议(如:com.baidu.tieba://app)
            window.setTimeout(function() {
                window.location.href = "https://****.apk";//android 下载地址
            }, 2000)    
        }
    };
</script>

欢迎分享本文,转载请保留出处:前端ABC » Js判定移动端是否安装app

赞 (1)
分享到:更多 ()

发表评论 0