【发布时间】:2016-06-23 11:14:09
【问题描述】:
我正在尝试重定向到自定义方案以深层链接到 iOS 和 Android 应用程序。行为是不同的跨浏览器,所以我试图找到一个一致的解决方案。下面是我在不同浏览器中的 jQuery 和行为。
$(document).ready(function (){
console.log(window.location.href);
window.location.href = window.location.href.replace('http','custom').replace('https','custom');
//I am waiting 2 seconds for this to succeed before trying to launch
device app store or www site if on an unsupported device/web browser
window.setTimeout(function(){
console.log(navigator.userAgent.toLowerCase());
if(navigator.userAgent.toLowerCase().indexOf("android") > -1){
console.log('Android');
window.location.href = 'https://play.google.com/store/apps/details?id=';
}else if(navigator.userAgent.toLowerCase().indexOf("iphone") > -1){
console.log('iOS');
window.location.href = 'https://itunes.apple.com/us/app/';
}else{
console.log('Other');
window.location.href = 'https://www.website.com';
}
},2000);
//wait for 2000 milliseconds before trying to redirect to stores.
//this is crap it would be better to wait for an error or respond
//to the Chrome External Protocol Request dialog
});
Chrome 启动外部协议请求对话框。如果这在 2 秒内没有响应,或者如果用户单击“什么都不做”,则重定向有效
Firefox 只是无法处理自定义 URL 方案并显示“地址不被理解”
IE 启动 App Store 对话框并成功重定向(!)
Safari 启动取消/选择应用程序/搜索 App Store 对话框,但不重定向。任何交互都会导致“Safari 无法打开指定地址”。
最好从相应的对话框中捕获事件(如果可能)以触发重定向。 2 秒等待是任意的,可能不会总是有效。
非常感谢任何帮助。
【问题讨论】:
标签: javascript android jquery ios internet-explorer