码迷,mamicode.com
首页 > 移动开发 > 详细

ios协议调起app

时间:2014-12-24 13:19:31      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:

function openIos(url, callback) {
    if (!url) {
        return;
    }
    var node = document.createElement(‘iframe‘);
    node.style.display = ‘none‘;
    var body = document.body;
    var timer;
    var clear = function(evt, isTimeout) {
       (typeof callback===‘function‘) &&  callback(isTimeout);
        window.removeEventListener(‘pagehide‘, hide, true);
        window.removeEventListener(‘pageshow‘, hide, true);
        if (!node) {
            return;
        }

        node.onload = null;
        body.removeChild(node);
        node = null;

    };
    var hide = function(e){
        clearTimeout(timer);
        clear(e, false);
    };
    window.addEventListener(‘pagehide‘, hide, true);
    window.addEventListener(‘pageshow‘, hide, true);
    node.onload = clear;
    node.src = url;
    body.appendChild(node);
    var now = +new Date();
    //如果事件失败,则1秒设置为空
    timer = setTimeout(function(){
        timer = setTimeout(function(){
          var newTime = +new Date();
          if(now-newTime>1300){
            clear(null, false);
          }else{
            clear(null, true);
          }

        }, 1200);
    }, 60);
}

  

ios协议调起app

标签:

原文地址:http://www.cnblogs.com/xiaohui108/p/4182107.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!