本功能主要用于手机端,如果手机未安装该APP,则跳转至下载页面;否则,直接打开手机中的APP。
<div style="position:absolute; top:84%; left:24%; z-index:8;"> <a id="J-call-app" href="javascript:;"><img src="image/but01.jpg"></a> <input id="J-download-app" type="hidden" name="storeurl" value="http://app.jiaxidezhou.com/jxmj.apk"> </div>
<script> //js 通过浏览器直接打开应用程序(IOS,Android) (function(){ var ua = navigator.userAgent.toLowerCase(); var t; var config = { /*scheme:必须*/ scheme_IOS: 'jiaximajiang://', scheme_Adr: 'jiaximajiang://splash', download_url: document.getElementById('J-download-app').value, timeout: 600 }; function openclient() { var startTime = Date.now(); var ifr = document.createElement('iframe'); ifr.src = ua.indexOf('os') > 0 ? config.scheme_IOS : config.scheme_Adr; ifr.style.display = 'none'; document.body.appendChild(ifr); var t = setTimeout(function() { var endTime = Date.now(); if (!startTime || endTime - startTime < config.timeout + 200) { window.location = config.download_url; } else { } }, config.timeout); window.onblur = function() { clearTimeout(t); } } window.addEventListener("DOMContentLoaded", function(){ document.getElementById("J-call-app").addEventListener('click',openclient,false); }, false); })() //JS判断微信、QQ内置浏览器,useragent window.onload = function (){ var ua = navigator.userAgent.toLowerCase(); var div = document.getElementById("here"); if(ua.match(/MicroMessenger/i)=='micromessenger' || ua.match(/QQ//i) == "qq/") { div.style.display = "block"; }else{ div.style.display = "none"; } } </script>
[参考]http://blog.csdn.net/coslay/article/details/46889051#t1