我一直在寻找一种从浏览器打开原生iOS应用程序的方法。我在这里找到了一个不错的解决方案:Is it possible to register a http+domain-based URL Scheme for iPhone apps, like YouTube and Maps?
当你安装了应用程序时,这个解决方案效果很好。但是当用户没有安装此应用程序时,safari会触发一条错误消息,提示"Safari无法打开页面,因为地址无效。“
有没有办法防止这种行为,而不是提示用户下载应用程序?
发布于 2014-07-31 17:04:26
这是一个适合我的解决方案:
var timeout;
function preventPopup() {
clearTimeout(timeout);
timeout = null;
window.removeEventListener('pagehide', preventPopup);
}
function openApp() {
$('<iframe />')
.attr('src', appurl)
.attr('style', 'display:none;')
.appendTo('body');
timeout = setTimeout(function() {
document.location = appstore;
}, 500);
window.addEventListener('pagehide', preventPopup);
} 发布于 2014-07-11 12:22:40
使用iframe。
$('<iframe />').attr('src', "appname://").attr('style', 'display:none;').appendTo('body');发布于 2015-06-03 19:32:44
为了解决这个问题并避免不想要的iOS safari警告,我使用了一种不同的方法来处理,也是一个iframe,但没有jquery和侦听器事件。它工作得很完美。
var iframe = document.createElement("iframe");
iframe.style.border = "none";
iframe.style.width = "1px";
iframe.style.height = "1px";
iframe.onload = function () {
document.location = alt;
};
iframe.src = nativeSchemaUrl; //iOS app schema url
window.onload = function(){
document.body.appendChild(iframe);
}
setTimeout(function(){
window.location = fallbackUrl; //fallback url
},300);https://stackoverflow.com/questions/19701708
复制相似问题