Created
December 12, 2013 05:29
-
-
Save ksky521/7923596 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/> | |
<title>ios调起实验 @三水清</title> | |
<script src="http://zeptojs.com/zepto.min.js"></script> | |
<style> | |
button{ | |
height: 80px; | |
width: auto; | |
} | |
#info{ | |
background:skyblue; | |
min-height: 50px; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>ios调起实验</h1> | |
<p>发现ios上面,schema调起存在alert的时候,执行不成功</p> | |
<h2>消息区域</h2> | |
<div id="info"> | |
</div> | |
<p> | |
<button id="btn">点我点我啊!alert</button> | |
</p> | |
<p> | |
<button id="btn2">点我点我啊!alert2</button> | |
</p> | |
<p> | |
<button id="btninfo">点我点我啊!info</button> | |
</p> | |
</body> | |
</html>` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function(){ | |
var $info = $('#info'); | |
function info(msg){ | |
var p = $('<p>'+msg+'</p>'); | |
$info.append(p); | |
} | |
$('#btn').on('click', function(){ | |
openIos('baiduboxapp://', function(t){ | |
if(t){ | |
alert('timeout or no baidu APP'); | |
}else{ | |
alert('invoke success'); | |
} | |
}); | |
}); | |
$('#btn2').on('click', function(){ | |
openIos('baiduboxapp://', function(t){ | |
if(t){ | |
info('timeout or no baidu APP2'); | |
alert('timeout or no baidu APP2'); | |
}else{ | |
info('invoke success2'); | |
alert('invoke success2'); | |
} | |
}); | |
}); | |
$('#btninfo').on('click', function(){ | |
openIos('baiduboxapp://', function(t){ | |
if(t){ | |
info('timeout or no baidu APP'); | |
}else{ | |
info('invoke success'); | |
} | |
}); | |
}); | |
}); | |
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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment