Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Equivalent to googlechrome://myurl.com for Safari

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!

like image 449
Valdir Amorim Avatar asked Nov 22 '18 16:11

Valdir Amorim


People also ask

What search engine does Safari use?

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.

Which browser is better Chrome or Safari?

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.

Is Safari or Chrome better on Mac?

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.

Does Chrome on iOS use Safari?

“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.”


1 Answers

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

like image 92
rma Avatar answered Sep 28 '22 06:09

rma