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); }
时间: 2024-10-08 14:30:28