时光轴

H5调起原生APP

2018-07-14  本文已影响3人  侯工

代码:

<a id="call-app" href="javascript:;" > Start or Download </a><br/><br/>
    <script type="text/javascript">
            (function(){
        var ua = navigator.userAgent.toLowerCase();
        var t;
        var config = {
                /*scheme:必须*/
                scheme_IOS: 'com.wntsvideo.com://',
                scheme_Adr: 'h5wants://wants.com/openwith?type=1&targetId=100469&targetTitle=aaa&targetContent=bbbb',
                download_url: 'http://a.app.qq.com/o/simple.jsp?pkgname=com.wants',
                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("call-app").addEventListener('click',
                    openclient, false);
        }, false);
    })()
    </script>

更多咨询请关注:
1、Git 汇总
2、VUE
3、前端开发

上一篇下一篇

猜你喜欢

热点阅读