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+  

猜你喜欢

转载自www.cnblogs.com/fanbi/p/9221596.html