Created
December 11, 2013 06:38
-
-
Save ksky521/7905967 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>JS Bin</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="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'); | |
} | |
}); | |
}); | |
$('#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) { | |
if (!node) { | |
return; | |
} | |
(typeof callback==='function') && callback(isTimeout); | |
node.onload = null; | |
body.removeChild(node); | |
node = null; | |
window.removeEventListener('pagehide', hide, false); | |
window.removeEventListener('pageshow', hide, false); | |
}; | |
var hide = function(e){ | |
clearTimeout(timer); | |
clear(e, false); | |
}; | |
window.addEventListener('pagehide', hide, false); | |
window.addEventListener('pageshow', hide, false); | |
node.onload = clear; | |
node.src = url; | |
body.appendChild(node); | |
//如果事件失败,则1秒设置为空 | |
timer = setTimeout(function(){ | |
timer = setTimeout(function(){ | |
clear(null, true); | |
}, 1200); | |
}, 60); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment