简体   繁体   English

在 Facebook 应用程序之外打开网站链接

[英]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:我已经找到了一种方法来检测页面是否已加载到 Facebook 应用程序中,这是通过以下方式完成的:

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.目标是要求用户通过浏览器加载页面,如果用户同意,则在 Safari、Chrome 或任何首选浏览器中打开页面。

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.在撰写本文时,据我所知,通过 JavaScript 代码无法实现您想要的结果。 The only options involve having the user configure or perform certain actions by themselves, and the options differ between iOS and Android.唯一的选项涉及让用户自己配置或执行某些操作,iOS 和 Android 之间的选项不同。 You can detect that the user is in the Facebook Internal browser and instruct the user on what to do next.您可以检测到用户在 Facebook 内部浏览器中,并指导用户下一步做什么。 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.对于 Android Facebook 应用程序:用户可以禁用内部浏览器:点击三行(三明治)菜单,向下滚动到设置和隐私,然后选择设置。 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".对于 iOS Facebook 应用程序:用户可以打开链接,然后点击右上角 (Facebook) 或右下角 (Messenger) 的三点菜单并选择“在 Safari 中打开”。


For Android , there is a workaround involving Firebase Dynamic Links - described here对于 Android ,有一个涉及 Firebase 动态链接的解决方法 -描述here

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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