9

(Before downvoting/flagging please note that there are already similar questions but none of them do work with plain javascript)

Whenever a Link on the Facebook-Feed is clicked on an iOS device (only via facebook app) it will open in a WebView and not in a new browser window (like it is on android).

When this happens, the web application that is about to be opened breaks, so I need to trick iOS somehow and force it to open the link in the users standard browser (where the web application works flawlessly).

If that's only possible when a button is klicked it would also be no problem. But from what I have tried everything opened in the WebView and I just could not get it managed to open it in the browser.

I've seen a couple of ObjectiveC solutions which I cannot of course make use of in a web application. So I'd like to stick to JS/HTML (or PHP but I don't think it will be much of a help)

What does not work:

<a href="http://google.com" target="_blank">My Link Text</a>

A normal link with the target attribute will not do the trick. The link will instead open within the WebView.

window.open('http://google.com');

window.open won't work neither (of course I've attached it to an event handler). It seems that the webview will not respond to window.open() anyways.

So anyone here who has a solution? I hope that's not some weird iOS guidline.

thpl
  • 5,810
  • 3
  • 29
  • 43
  • There is a trick actually, see this: https://stackoverflow.com/questions/53025910/js-open-safari-from-any-browser – Goon Nguyen Oct 29 '18 at 08:03

1 Answers1

4

This behaviour is controlled by the Facebook app. There is an explicit call on iOS to open a URL with the system tool (such as Safari for regular web addresses). If the Facebook app is opening URLs via its in-built web view then there isn't much you can do

Paulw11
  • 108,386
  • 14
  • 159
  • 186
  • Thanks for the clarification. I solved it by reading the user agent that differs from within the webview and showing different conent – thpl Apr 04 '14 at 11:59
  • I had to detect FB webview as well, thanks to this post: [detect Facebook Browser](http://stackoverflow.com/questions/31569518/how-to-detect-facebook-in-app-browser). To get a new window open, we had to wrap a location.href call in a setTimeout. Gross but effective :( `if (isFacebookApp()) { setTimeout(function(){ location.href = url; }, 500); } ` – mrdougwright Oct 18 '16 at 18:54
  • 4
    @mrdougwright I'm able to detect if I am in the Facebook in-app browser but then how do you manage to open a link into another browser (native, chrome or safari for instance) ? `location.href` only change the URL but navigation stays into the Facebook in-app browser. – gowithefloww Sep 02 '17 at 15:45