简体   繁体   中英

Open website link outside of Facebook app

I already found a way to detect if the page has been loaded inside of the Facebook app, which is done this way:

var ua = navigator.userAgent || navigator.vendor || window.opera;
if((ua.indexOf("FBAN") > -1) || (ua.indexOf("FBAV") > -1)) {
    var openInBrowser = window.confirm("This page works best outside of the Facebook app. Do you want to open it in your browser instead?");
    if (openInBrowser) {
        window.open(
          window.location.href, 
          '_blank'
        );
    }
}

However, this script does not seem to work. Is it because the phone blocks it (pop-up blocker)? The objective is to ask the user to load the page through the browser instead, if the user agrees, then open the page in Safari, Chrome or whatever is the preferred browser.

I know it is late, but I had this problem recently and I think my answer might be of use to people with the same problem.

As of the time of writing, and to my knowledge, It is not possible to achieve your desired result from JavaScript code. The only options involve having the user configure or perform certain actions by themselves, and the options differ between iOS and Android. You can detect that the user is in the Facebook Internal browser and instruct the user on what to do next. This is unfortunately poor user experience.


For the Android Facebook App: The user can disable internal browser:Tap on the triple-line (sandwich) menu, scroll down to Settings & Privacy, and choose Settings. Again, scroll all the way down to Media & Contacts. Here, you will see a "Links open externally" toggle. This needs to be on.

For the iOS Facebook app: The user can open up the link, then tap on the triple-dot menu either at the top right (Facebook) or bottom right (Messenger) and choose "Open in Safari".


For Android , there is a workaround involving Firebase Dynamic Links - described here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM