I am having some issues with my webapp where if the user clicks the link from Facebook app it will use it's own browser/webview, but it is required to use Safari or Chrome in order to run the page.
While researching (this issue), I found that you can use googlechrome://navigate?url=example.com from a Android device to open chrome, and googlechrome://myurl.com from a iOS to open Chrome aswell, but I need a way to open Safari if the user's device is iOS.
Is there a way to do so?
Ps.: The link the user clicks in Facebook goes to a landing page, and in this page there is a button to the webapp. When the user clicks this button I will open Chrome/Safari.
Thanks in advance!
Google Search is the default search engine on Safari for iOS. Here are the detailed steps on how to change it to a different one. When users type a search term in Safari for iOS, the app displays Google Search results.
Chrome, as you might guess, is certainly a better fit if you have Android devices or use Windows operating system (there's no Safari for Windows). It also works seamlessly with Chromecast so you can easily stream anything from your computer to your TV.
In fact, Safari beats Chrome on the Mac because it's more energy-efficient, better at protecting your privacy, and it seamlessly works with the Apple ecosystem. Here are all the reasons why you should avoid using Google Chrome on your Mac.
“Because at the moment, every browser on iOS, whether it be badged Chrome, Firefox or Edge is actually just a branded skin of Safari, which lags behind [other browsers] because it has no competition on iOS.”
There are a few answers across SO with a similar topic. Something along the lines of
NSString *yourUrl = @"http://yourURL";
SFSafariViewController *svc= [[SFSafariViewController alloc] initWithURL:[NSURL URLWithString: yourUrl]];
[self presentViewController:svc animated:YES completion:nil];
In Swift, that's
let yourUrl = "http://www.yourURL.com";
let svc = SFSafariViewController.init(url: URL);
svc.delegate = self
present(svc, animated: true);
should work.
If you're using Javascript, take a look at Force link to open in mobile safari from a web app with javascript
It seems you need to do something like
HTML:
<div id="foz" data-href="http://www.google.fi">Google</div>
JS:
document.getElementById("foz").addEventListener("click", function(evt) {
var a = document.createElement('a');
a.setAttribute("href", this.getAttribute("data-href"));
a.setAttribute("target", "_blank");
var dispatch = document.createEvent("HTMLEvents");
dispatch.initEvent("click", true, true);
a.dispatchEvent(dispatch);
}, false);
Test it at (http://www.hakoniemi.net/labs/linkkitesti.html)
Sources:
Open links in Safari instead of UIWebVIew?
How to force links to open in iOS Safari?
https://www.hackingwithswift.com/example-code/uikit/how-to-use-sfsafariviewcontroller-to-show-web-pages-in-your-app
Force link to open in mobile safari from a web app with javascript
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With