html 代码
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <meta name="viewport" content="initial-scale=1.0,user-scalable=no">
- <title>Js 判定移动端是否安装 app, 若已安装, 则打开, 未安装则跳转到下载页面 </title>
- <meta name='apple-itunes-app' content='app-id=1221201728'>
- </head>
- <body>
- <a href="javascript:;" id="openApp"> 点击打开安装 app</a>
- </body>
- </html>
- <script type="text/javascript">
- document.getElementById('openApp').onclick = function(e){
- if(navigator.userAgent.match(/(iPhone|iPod|iPad);?/i))
- {
- window.location.href = "com.baidu.tieba://";//ios app 协议 (如: com.baidu.tieba://)
- window.setTimeout(function() {
- window.location.href = "https://itunes.apple.com/cn/app/id477927812"; // 跳转到 App store
- }, 2000)
- }
- if(navigator.userAgent.match(/android/i))
- {
- window.location.href = "com.baidu.tieba://app";//android app 协议 (如: com.baidu.tieba://app)
- window.setTimeout(function() {
- window.location.href = "https://****.apk";//android 下载地址
- }, 2000)
- }
- };
- </script>
来源: http://www.qdfuns.com/article/41500/e10111fc18eb087ac2cb6e7cade3f2ac.html