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+
