这里有很多主题,但它们都需要本机代码交互才能工作。
在我的情况下,有必要直接从网址进行,而不与我的移动应用程序进行任何交互。
我试过了:
<a href="safari://google.com" target="_blank">Open Google in Safari</a>
和
<a href="webkit://google.com" target="_blank">Open</a>
并以this post为基地。
<script>
$(document).on('click', 'a[target="_blank"]', function (ev) {
var url;
ev.preventDefault();
url = $(this).attr('href');
window.open(url, '_system');
});
</script>
但没有任何作用。
任何人都知道如何解决这个问题?
有一个技巧。我们知道iOS Safari有这些可用的URL方案:
(HTTP) - http://websiteurl(HTTPS) - https://websiteurl x-web-search://(FTP) - ftp://locationtofileonftpserver
如果你使用Click here或window.open(“http://somewebsite”)。它总是使用当前浏览器打开URL。
x-web-search://?[keyword] - 它将切换到Safari应用程序但搜索关键字
幸运的是我们仍然有ftp:// left。它将切换到Safari应用程序。但首先,您需要在托管中设置公用文件夹并创建桥接html文件以将用户重定向回http:
FTP:// {} youripaddress /bridge.html
window.open("https://yoururl", "_self");现在,您可以从任何浏览器在默认的Safari应用程序中打开您的网站。
如果这是在safari中运行,它应该符合关于弹出窗口的safari异步调用限制为explained here。
你应该修改你的代码,以便打开的窗口将在函数之外,像这样:
<script>
var windowReference = window.open();
$(document).on('click', 'a[target="_blank"]', function (ev) {
var url;
ev.preventDefault();
url = $(this).attr('href');
windowReference.location = url;
});
</script>
iOS上没有适用于Safari的URL方案。
搜索一下,你会看到类似的答案:What is Mobile Safari's custom URL Scheme?