欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

通過(guò)掃描二維碼打開(kāi)app的實(shí)現(xiàn)代碼

 更新時(shí)間:2016年11月10日 17:06:31   作者:DOM先生  
在項(xiàng)目開(kāi)發(fā)中遇到這樣的需求,掃描二維碼打開(kāi)app如果用戶沒(méi)有這個(gè)app則提示它跳轉(zhuǎn),怎么實(shí)現(xiàn)呢?下面小編給大家分享通過(guò)掃描二維碼打開(kāi)app的實(shí)現(xiàn)代碼,感興趣的朋友參考下吧

最近有朋友問(wèn)小編這樣一個(gè)問(wèn)題,先給大家說(shuō)下項(xiàng)目需求:掃描二維碼打開(kāi)app如果用戶沒(méi)有這個(gè)app則提示它跳轉(zhuǎn)。

用網(wǎng)頁(yè)直接來(lái)調(diào)用app是不打可能的,必須原生那邊先做一些配置。

首先,安卓和蘋(píng)果的調(diào)用方法是不同的。

所以我們需要先判斷一下終端。

var u = navigator.userAgent,
app = navigator.appVersion;
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //android終端或者uc瀏覽器
var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios終端

之后最好是分別跳轉(zhuǎn)到兩個(gè)不同的頁(yè)面去做操作,因?yàn)樘O(píng)果需要在頭部配置一個(gè)app-id<meta name='apple-itunes-app' content='app-id=1115968341'>

下面是蘋(píng)果的代碼

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name='apple-itunes-app' content='app-id=1115968341'>
<title></title>
</head>
<body>
<a  id="openApp">點(diǎn)擊打開(kāi)</a>
<script type="text/javascript"> 
//蘋(píng)果
document.getElementById('openApp').onclick = function(e){ 
// 通過(guò)iframe的方式試圖打開(kāi)APP,如果能正常打開(kāi),會(huì)直接切換到APP,并自動(dòng)阻止a標(biāo)簽的默認(rèn)行為 
// 否則打開(kāi)a標(biāo)簽的href鏈接 
var ifr = document.createElement('iframe'); 
ifr.src = 'iosefunbox://'; 
ifr.style.display = 'none'; 
document.body.appendChild(ifr); 
window.setTimeout(function(){ 
document.body.removeChild(ifr); 
},3000) 
};
</script>
</body>
</html>

這里的ifr.src就是你去打開(kāi)app的協(xié)議路徑,安卓和蘋(píng)果是不一樣的。<br><br><br>如果是安卓機(jī)的話就簡(jiǎn)單了

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
</head>
<body>
<a  id="openApp">點(diǎn)擊打開(kāi)</a>
<script type="text/javascript">
//安卓
// /**/window.location.;
// 通過(guò)iframe的方式試圖打開(kāi)APP,如果能正常打開(kāi),會(huì)直接切換到APP,并自動(dòng)阻止a標(biāo)簽的默認(rèn)行為 
// 否則打開(kāi)a標(biāo)簽的href鏈接 
var ifr = document.createElement('iframe'); 
ifr.src = 'efunbox://efunbox.app/efunbox/open'; 
ifr.style.display = 'none'; 
document.body.appendChild(ifr); 
window.setTimeout(function(){ 
document.body.removeChild(ifr); 
},3000);
</script>
</body>
</html>

這是我們?cè)鹊男枨?,后?lái)變了,說(shuō)蘋(píng)果直接跳轉(zhuǎn)到appstore里面就好了,不用直接打開(kāi),安卓的話需要直接打開(kāi)。

這樣我就直接把它們集合在一個(gè)網(wǎng)頁(yè)就行。

我上面的a鏈接是直接跳轉(zhuǎn)到騰訊應(yīng)用寶里面。

用網(wǎng)頁(yè)掃描訪問(wèn)的話是沒(méi)問(wèn)題的,

但是我就感覺(jué)會(huì)出事,后來(lái)拿微信掃一掃就蒙逼了。安卓只會(huì)打開(kāi)a鏈接,跳轉(zhuǎn)不進(jìn)app,因?yàn)楸晃⑿艛r截掉了,蘋(píng)果也一樣,解決的方案只能是點(diǎn)擊右上角,提示用戶在瀏覽器打開(kāi)就沒(méi)問(wèn)題。這種方法是無(wú)奈之舉,但后來(lái)針對(duì)蘋(píng)果機(jī)找到了一個(gè)解決它的方案就是,a鏈接的跳轉(zhuǎn)直接跳騰訊應(yīng)用寶上架的鏈接,然后微信內(nèi)部會(huì)處理幫你自動(dòng)跳轉(zhuǎn)到appstore里面。

最后是整合了一下的代碼。

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body id="body">
<script type="text/javascript">
var u = navigator.userAgent,
app = navigator.appVersion;
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //android終端或者uc瀏覽器
var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios終端
if(isIOS){
window.location.; 
}
if(isAndroid){
alert("請(qǐng)點(diǎn)擊右上角在瀏覽器打開(kāi)");
window.location.;
var ifr = document.createElement('iframe'); 
ifr.src = 'efunbox://efunbox.app/efunbox/open'; 
ifr.style.display = 'none'; 
document.body.appendChild(ifr); 
window.setTimeout(function(){ 
document.body.removeChild(ifr); 
},3000);
}
</script>
</body>
</html>

補(bǔ)充:

掃描二維碼跳轉(zhuǎn)app

1、判斷是否安裝了app

<html> 
<head> 
<meta name="viewport" content="width=device-width" /> 
</head> 
<body> 
<h2><a id="applink1" href="mtcmtc://profile/116201417">Open scheme(mtcmtc) defined in iPhone with parameters </a></h2> 
<h2><a id="applink2" href="unknown://nowhere">open unknown with fallback to appstore</a></h2> 
<p><i>Only works on iPhone!</i></p> 
<script type="text/javascript"> 
// To avoid the "protocol not supported" alert, fail must open another app.
var appstore = "itms://itunes.apple.com/us/app/facebook/id284882215?mt=8&uo=6";
function applink(fail){
return function(){
var clickedAt = +new Date;
// During tests on 3g/3gs this timeout fires immediately if less than 500ms.
setTimeout(function(){
// To avoid failing on return to MobileSafari, ensure freshness!
if (+new Date - clickedAt < 2000){
window.location = fail;
}
}, 500); 
};
}
document.getElementById("applink1").onclick = applink(appstore);
document.getElementById("applink2").onclick = applink(appstore);
</script> 
</body> 
</html>

2、打開(kāi)項(xiàng)目工程target里面的schemurl追加://

以上所述是小編給大家介紹的通過(guò)掃描二維碼打開(kāi)app的實(shí)現(xiàn)代碼,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論