js喚醒手機APP

來源:互聯網
上載者:User

標籤:nav   animation   not   function   span   script   com   pen   預設   

if (navigator.userAgent.match(/android/i)) {
// 通過iframe的方式試圖開啟APP,如果能正常開啟,會直接切換到APP,並自動阻止a標籤的預設行為
// 否則開啟a標籤的href連結
var isInstalled;
//下面是安卓端APP介面調用的地址,自己根據情況去修改
var ifrSrc = ‘cartooncomicsshowtwo://platformapi/startApp? type=0&id=${com.id}&phone_num=${com.phone_num}‘;
var ifr = document.createElement(‘iframe‘);
ifr.src = ifrSrc;
ifr.style.display = ‘none‘;
ifr.onload = function() {
// alert(‘Is installed.‘);
isInstalled = true;
alert(isInstalled);
document.getElementById(‘openApp0‘).click();};
ifr.onerror = function() {
// alert(‘May be not installed.‘);
isInstalled = false;
alert(isInstalled);
}
document.body.appendChild(ifr);
setTimeout(function() {
document.body.removeChild(ifr);
},1000);
}
//ios判斷
if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)){
if (navigator.userAgent.match(/(iPhone|iPod|iPad);?/i)) {
//Animation://com.yz.animation
var isInstalled;
//var gz = ‘{"comName":"${com.short_name}","comID":"${com.id}","comPhoneNum":"${com.phone_num}","type":"0"}‘;
//var jsongz =JSON.parse(gz);

//下面是IOS調用的地址,自己根據情況去修改
var ifrSrc = ‘Animation://?comName=${com.short_name}&comID=${com.id}&comPhoneNum=${com.phone_num}&type=0‘;var ifr = document.createElement(‘iframe‘);
ifr.src = ifrSrc;
ifr.style.display = ‘none‘;
ifr.onload = function() {
// alert(‘Is installed.‘);
isInstalled = true;
alert(isInstalled);
document.getElementById(‘openApp1‘).click();};
ifr.onerror = function() {
// alert(‘May be not installed.‘);
isInstalled = false;
alert(isInstalled);
}
document.body.appendChild(ifr);
setTimeout(function() {
document.body.removeChild(ifr);
},1000);
}
}

下面這個IOS可用,安卓不可用

<meta name=‘apple-itunes-app‘ content=‘app-id=477927812‘>

  1. <!-- a標籤的連結,設定為對應的下載連結;點擊開啟的動作,在click事件中註冊 -->  
  2. <a href="https://itunes.apple.com/cn/app/id477927812" id="openApp">貼吧用戶端</a>  
  3. <script type="text/javascript">  
  4.     document.getElementById(‘openApp‘).onclick = function(e){  
  5.         // 通過iframe的方式試圖開啟APP,如果能正常開啟,會直接切換到APP,並自動阻止a標籤的預設行為  
  6.         // 否則開啟a標籤的href連結  
  7.         var ifr = document.createElement(‘iframe‘);  
  8.         ifr.src = ‘com.baidu.tieba://‘;  
  9.         ifr.style.display = ‘none‘;  
  10.         document.body.appendChild(ifr);  
  11.         window.setTimeout(function(){  
  12.             document.body.removeChild(ifr);  
  13.         },3000)  
  14.     };  
  15. </script>  

js喚醒手機APP

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.