在Facebook应用程序外部打开网站链接 [英] Open website link outside of Facebook app

查看:455
本文介绍了在Facebook应用程序外部打开网站链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经找到一种方法来检测页面是否已加载到Facebook应用程序内部,方法是通过这种方式完成的:

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'
        );
    }
}

但是,此脚本似乎不起作用.是因为电话阻止了它(弹出窗口阻止程序)?目的是要求用户改为通过浏览器加载页面,如果用户同意,则在Safari,Chrome或任何首选的浏览器中打开页面.

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.

截至撰写本文时,据我所知,无法通过JavaScript代码获得所需的结果.唯一的选项涉及让用户自己配置或执行某些操作,并且这些选项在iOS和Android之间有所不同. 您可以检测到用户在Facebook内部浏览器中,并指导用户下一步如何做.不幸的是,这是糟糕的用户体验.

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.

对于Android Facebook应用: 用户可以禁用内部浏览器:在三行(三明治)菜单上点按,向下滚动到设置"和隐私,然后选择设置.再一次,一直向下滚动到Media&通讯录.在这里,您将看到外部链接打开"切换.这需要打开.

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.

对于iOS Facebook应用: 用户可以打开链接,然后点击右上角(Facebook)或右下角(Messenger)的三点菜单,然后选择在Safari中打开".

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".

对于Android ,存在涉及Firebase动态链接的解决方法-此处介绍

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

这篇关于在Facebook应用程序外部打开网站链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆