17

I'm developing web app and I share my contents using Facebook, the issue I'm facing is when someone clicks on the link posted on Facebook sometimes it opens using Facebook in app browser and that causes many issues.

Is there a way to prevent Facebook from opining my links and use the device default browser instead?

Mustafa Dwaikat
  • 3,392
  • 9
  • 27
  • 41
  • How about covering the page with a modal popup asking people to open the link in their external browser? – Dan Dec 30 '16 at 11:16

5 Answers5

11

I couldn't get my js dynamic grid to run in the Facebook in-app browser, but I couldn't just leave it up to the user to figure out what was wrong and that they needed to open in a real browser.

I used js to detect the Facebook in-app browser and tried using a js alert to inform the user that they needed to 'open in safari', but alerts don't work consistently or reliably with the Facebook in-app browser.

I found that a redirect to a user alert page was the most reliable solution. It can be presented as you wish (modal, etc.) A code sample for the redirect is included. Note that the redirect page remains within the Facebook browser - only user interaction can break out. I used my redirect page to tell people to use the 'share > open in Safari' function.

When the user clicks on 'open in safari', the redirect page reloads in safari, detects that it is now NOT in the Facebook in-app browser, and automatically redirects the user back to the page they wanted in the first place, but no longer from within the Facebook in-app browser. A "one-click" workaround to get the user out of that in-app browser.

The best solution would still be for my js grids to 'just work' in the Facebook browser some day. If anyone figures it out, let me know.

<!-- check if running in facebook app -->
    <script>

    var ua = navigator.userAgent || navigator.vendor || window.opera;

    function isFacebookApp() {
        return (ua.indexOf("FBAN") > -1) && (ua.indexOf("FBAV") > -1);
    }

    if (isFacebookApp()) {
        window.parent.location.assign("https://yourdomain.com/redirect_page/index.html");
    }

    </script>
János
  • 32,867
  • 38
  • 193
  • 353
Mcbeese
  • 143
  • 1
  • 12
7

It is completely up to the user, there is no way to force opening it in the default browser instead. There is more information (and some answers) in this thread: File upload control not working in Facebook In-App Browser

Community
  • 1
  • 1
andyrandy
  • 72,880
  • 8
  • 113
  • 130
  • 3
    this answer says "no way" and yet the answer below it clearly demonstrates "a way". Why is this the accepted answer? – Jason FB Jun 07 '17 at 16:37
  • 1
    With some research, we feel that detecting the user agent and then showing a pop-up or modal informing the user to switch into the real Safari browser is "the way" to do it. So I am downvoting this answer because it is clearly false — there is "a way" — it's just not a technical way, it is a user-interaction way. – Jason FB Jun 07 '17 at 16:43
  • 2
    sorry, but that does not make my answer wrong. you still can´t "force" it, and the question was about completely avoiding it. – andyrandy Jun 07 '17 at 18:27
  • You are indeed correct there is no way to "force" the user out of the in-app browser – Jason FB Jun 12 '17 at 17:33
  • what way exactly? if you mean the other answers, that´s not really a solution. of course you can detect the facebook browser and redirect to some page, but it will still happen in that facebook browser. the question is how to "prevent" it from even happening, which is not possible. – andyrandy Nov 05 '18 at 16:37
1

OR... be less complicated. Why have a function called isFacebookApp() at all, and why target Opera when you are looking only for the FB in-app browser only?

<script>
  var ua = navigator.userAgent;

  if (ua.indexOf("FBAN") != -1 || ua.indexOf("FBAV") != -1) {
    if (!window.location.href.match('redirect_fb')) {
      window.location.href = "https://example.com/redirect_fb";
    }
  }

</script>

Thank you to both of you though. This was driving me nuts. My main problem was fonts being enlarged on my Android. Now I find reducing with a fontsz = Math.round(fontsz*.7)is perfect to counteract (when FB app detected)

0

Based on Mcbeese

<!-- check if running in facebook app -->
    <script>

    var ua = navigator.userAgent || navigator.vendor || window.opera;

    function isFacebookApp() {
        return (ua.indexOf("FBAN") > -1) || (ua.indexOf("FBAV") > -1);

    }

    if (isFacebookApp()) {
      if (!window.location.href.match('redirect_fb')) {
        window.location.href = "https://example.com/redirect_fb";
      }
    }

    </script>
Arne Jenssen
  • 1,235
  • 3
  • 14
  • 22
0

I found that Android will open Firebase Dynamic Links by external browser regardless of which kind of webview the url was posted.

I wrote a more detailed description at https://stackoverflow.com/a/56143217/3000586.

starshine wang
  • 616
  • 1
  • 8
  • 13