admin管理员组文章数量:1241079
There are many topics of this here, but they all need native code interaction to work.
In my case, it is necessary to be able to do it directly from the url, without any interaction with my mobile app.
I tried:
<a href="safari://google" target="_blank">Open Google in Safari</a>
and
<a href="webkit://google" target="_blank">Open</a>
and based in this post.
<script>
$(document).on('click', 'a[target="_blank"]', function (ev) {
var url;
ev.preventDefault();
url = $(this).attr('href');
window.open(url, '_system');
});
</script>
but nothing works.
Anyone have any idea how to fix this?
There are many topics of this here, but they all need native code interaction to work.
In my case, it is necessary to be able to do it directly from the url, without any interaction with my mobile app.
I tried:
<a href="safari://google." target="_blank">Open Google in Safari</a>
and
<a href="webkit://google." target="_blank">Open</a>
and based in this post.
<script>
$(document).on('click', 'a[target="_blank"]', function (ev) {
var url;
ev.preventDefault();
url = $(this).attr('href');
window.open(url, '_system');
});
</script>
but nothing works.
Anyone have any idea how to fix this?
Share Improve this question asked Jul 28, 2017 at 17:05 jose920405jose920405 8,0596 gold badges47 silver badges75 bronze badges 4-
I think the url scheme should be
-apple-mobilesafari-tab://
. – Etienne Martin Commented Aug 3, 2017 at 15:53 - Is this a cordova/phonegap app? – catbadger Commented Aug 8, 2017 at 15:47
- @catbadger it's not relevant, because i don't need any code from mobile app. – jose920405 Commented Aug 8, 2017 at 16:26
- -apple-mobilesafari-tab no longer works as of ios 17.5 – ina Commented Jun 15, 2024 at 1:29
3 Answers
Reset to default 7There is a trick. We know iOS Safari have these available URL Schemes:
(HTTP) — http://websiteurl (HTTPS) — https://websiteurl x-web-search:// (FTP) — ftp://locationtofileonftpserver
If you use Click here or window.open("http://somewebsite"). It always use current browser to open url.
x-web-search://?[keyword] - It will switch into Safari app but search for the keyword
Luckily we still have ftp:// left. It will switch to Safari app. But first you need to setup a public folder in your hosting & create a bridge html file to redirect user back to http:
ftp://{youripaddress}/bridge.html
window.open("https://yoururl", "_self");Now you can open your website in the default Safari app from any browsers.
The original answer is here: JS - Mobile - Open Safari from any browser
Update (2021-01): Apple seems to fix this on iOS, this is no longer work!
If this is running in safari it should ply with safari async call restrictions regarding popups as explained here.
You should fix your code so that the window open will be outside the function, Something like that:
<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>
There isn't a URL Scheme for Safari on iOS.
See Apple's Documentation: https://developer.apple./library/archive/featuredarticles/iPhoneURLScheme_Reference/Introduction/Introduction.html
Have a search around and you will see similar answers: What is Mobile Safari's custom URL Scheme?
本文标签: javascriptHow open link in safari mobile app from webviewStack Overflow
版权声明:本文标题:javascript - How open link in safari mobile app from webview - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740102310a2224652.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论