美文网首页时光轴
H5调起原生APP

H5调起原生APP

作者: 侯工 | 来源:发表于2018-07-14 15:10 被阅读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、前端开发

    相关文章

      网友评论

        本文标题:H5调起原生APP

        本文链接:https://www.haomeiwen.com/subject/vlrypftx.html