Android/IOS 微信及瀏覽器(h5)中喚起本地APP,喚起浮層,然后用外部瀏覽器打開喚起某本地APP


1 前言

微信點擊鏈接,點擊喚起某APP,在微信點開,默認是微信瀏覽器,點擊button喚起,則會先提示浮層,然后用外部瀏覽器打開即可。

作為記錄使用。

2 代碼

相關源碼如下:

html:

<div class="container">
   <div class="main" >
     <div class="enterBtn" onclick="triggerStart()">
     </div>
    </div>
   <div class="openTip"  id="openTip">  </div>
</div>

Javascipt:  

    
function IsIosAndroid(){
if((/android/gi).test(navigator.appVersion)){
        return 1;
    }else if((navigator.userAgent.indexOf('iPhone') != -1) || (navigator.userAgent.indexOf('iPod') != -1) || (navigator.userAgent.indexOf('iPad') != -1)){
        return 2;
    }
}

function openAndroid()
{
      //appAndroid://a.b.com是某APP喚起的方式	
      window.location.href ="appAndroid://a.b.com";
	
}

function openIos()
{     
        //appios 是某APP喚起的方式
	window.location.href = "appios://";
}

function is_weixn(){
    var ua = navigator.userAgent.toLowerCase();
    if(ua.match(/MicroMessenger/i)=="micromessenger") {
        return true;
    } else {
        return false;
    }
}


function triggerStart(){

    if(IsIosAndroid()==1){
        if(is_weixn())
        {
            document.getElementById("openTip").style.backgroundImage="url(../images/fuceng.png)";
            document.getElementById("openTip").style.display='block';
            return;
        }
        openAndroid();
    }else if(IsIosAndroid()==2){
        if(is_weixn())
        {
            document.getElementById("openTip").style.backgroundImage="url(../images/fuceng.png)";
            document.getElementById("openTip").style.display='block';
            return;
        }
        openIos();
    }
}

3 小結

IOS9之前的 喚起方式不太一樣,本文的ios系統為IOS10+  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM