若有安裝APP, 自動開啟(使用 URL Schema), 若無, 則詢問是否到商店進行下載。

原理:用瀏覽器開啟下載html, 利用javascript判斷。 
  無標題

<html>
<head>
<title>判斷是否有安裝APP,若無,則詢問是否下載</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="images/css.css" rel="stylesheet" type="text/css">
<script language="JavaScript" type="text/JavaScript">
    var isiPad = navigator.userAgent.match(/iPad/i) != null;
    var isiPhone = navigator.userAgent.match(/iPhone/i) != null;
    var isandroid = navigator.userAgent.match(/Android/i) != null;
    
    if(isandroid)
    {
        window.location.href='https://play.google.com/store/apps/details?id=com.fonestock.android.yourapp';
    }
    if(isiPad)
    {
        document.location = 'yourappurls://'; 
        setTimeout( function() { 
            if( confirm( '您似乎沒有安裝, 這個APP, 進行下載?')) { 
                document.location = 'http://itunes.apple.com/tw/app/id4179293XX'; 
            } 
        }, 300);
    }
    if(isiPhone)
    {
        document.location = 'yourappurls://'; 
        setTimeout( function() { 
            if( confirm( '您似乎沒有安裝, 這個APP, 進行下載?')) { 
                document.location = 'http://itunes.apple.com/tw/app/id4179293XX'; 
            } 
        }, 300);
    }
 
 
</script>
 
</head>
<body>
 
</body>
</html>

猜你喜欢

转载自duchengjiu.iteye.com/blog/1972484