Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent Facebook in app browser from opening my website links?

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?

like image 399
Mustafa Dwekat Avatar asked Apr 04 '16 12:04

Mustafa Dwekat


Video Answer


2 Answers

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>
like image 99
Mcbeese Avatar answered Oct 05 '22 07:10

Mcbeese


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

like image 37
andyrandy Avatar answered Oct 05 '22 07:10

andyrandy