<script> var userAgent=navigator.userAgent; var src="https://www.collegemew.com"; var appLink=""; var openApp=false; if(userAgent.indexOf("MicroMessenger")!=-1) {//weChat 会拦截 openApp=false; } else if(userAgent.indexOf("OS")!=-1) {//iPhone OS,CPU OS(ipad) openApp=true; appLink="collegemew://"; } else if(userAgent.indexOf("Android")!=-1) { openApp=true; appLink="mew://collegemew"; } $(document).ready(function() { if(openApp) { $("button[name='download']").click(function() { var ifr = document.createElement('iframe'); ifr.src = appLink; ifr.style.display = 'none'; ifr.onerror = function() { location.href=src; } document.body.appendChild(ifr); }); } else { $("button[name='download']").click(function() { location.href=src; }); } }); </script>
点击页面判断是否安装app并打开,否则跳转app store的方法
最后发现微信跳转无效,qq iphone必须a标签href=”“才能跳转,所以直接跳官网了