How to open link in mobile Safari app from webview
There are many topics here, but they all need code sharing.
In my case, I need to be able to do this directly from the URL, without any interaction with my mobile app.
I tried:
<a href="safari://google.com" target="_blank">Open Google in Safari</a>
and
<a href="webkit://google.com" target="_blank">Open</a>
and is based on 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.
Does anyone know how to fix this?
source to share
If it works on safari, it must comply with Safari's asynchronous popup restrictions as described here .
You have to fix your code so that the open window is outside the function, something like this:
<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>
source to share
There is a trick. We know that iOS Safari has the following URL schemes available:
(HTTP) - http: // websiteurl (HTTPS) - https: // websiteurl x-web-search: // (FTP) - ftp: // locationtofileonftpserver
If you are using Click here or window.open (" http: // somewebsite "). It always uses the current browser to open the URL.
x-web-search: //? [keyword] - it will switch to the Safari app but search for the keyword
Luckily, we still have ftp: // left. It will switch to the Safari app. But first, you need to set up a shared folder on your hosting and create a bridging html file to redirect the user back to http:
FTP: // {} youripaddress / bridge.html
window.open ("https: // yoururl", "_self");You can now open your website in the standard Safari app from any browser.
Original answer here: JS - Mobile - Open Safari from any browser
source to share
No URL scheme for Safari on iOS.
See Apple documentation: https://developer.apple.com/library/archive/featuredarticles/iPhoneURLScheme_Reference/Introduction/Introduction.html.
Do a search and you will see similar answers: What is Mobile Safari's custom URL scheme?
source to share