html启动android程序

  • 内容
  • 评论
  • 相关

html代码

<!DOCTYPE HTML>
<html lang="en-US">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no" />
    <title>启动本地app</title>
    <script type="text/javascript" src="../lib/core/jquery-1.8.3.js"></script>
    <script type="text/javascript">
    $(function () {
        var timeout, t = 1000, hasApp = true;
        setTimeout(function () {
            if (hasApp === false) {
                forceDownload();
            }
        }, 2000)
        function testApp() {
            var t1 = Date.now();
            var ifr = $('<iframe id="ifr" style="display:none;"></iframe>')
            ifr.attr('src', 'hicampus://koosoft.cn');
            $('body').append(ifr);
            timeout = setTimeout(function () {
                try_to_open_app(t1);
            }, t);
        }
        function try_to_open_app(t1) {
            var t2 = Date.now();
            if (!t1 || t2 - t1 < t + 100) {
                hasApp = false;
            }
        }
        function forceDownload(){
            window.location.href = 'http://hi.koosoft.cn/download.html';
        }
       
        //执行
        testApp();
    });

    </script>
</head>
<body>
    <h1>启动本地app</h1>
</body>
</html>