Facebook Like 按钮弹出窗口无法加载

发布于 2024-12-13 16:08:23 字数 2907 浏览 0 评论 0原文

这是我的第一个问题,所以如果我遗漏了细节,请宽容一点。谢谢!

我在我的网站上使用 Facebook Like Button 插件(尝试了 HTML5 版本和 xfbml 版本)。我已经包含了 xfbml 和 HTML5 支持所需的所有标签和脚本。我已遵循“规范”,并在此处和其他地方对问题进行了彻底的搜索:

“like”按钮功能正常,但单击按钮后应显示的弹出窗口/弹出窗口未加载。我的意思是加载,而不是显示(是的,我已经根据规范)。新的 (包括 )会在 Like 按钮 之后立即添加到 DOM ,并且它们加载了应该存在的所有代码:

<span class=" fb_edge_comment_widget fb_iframe_widget " style="top: 19px; left: 0px; z-index: 10000;">
  <span>
    <iframe id="fa02aa64d8da" class="fb_ltr" scrolling="no" name="fee6eb9f6f2768" style="border: medium none; overflow: hidden; height: 225px; width: 401px;" src="http://www.facebook.com/plugins/comment_widget_shell.php?api_key=233493930007947&locale=en_US&master_frame_name=fa12240bc73214&sdk=joey">
      <html>
        <head>
        <body onload="onPageLoad()">
          <script>
            var onPageLoad = function() {
              document.domain = 'facebook.com';
              var loc = window.location.toString();
              var index = loc.indexOf('?');
              var qs = loc.substring(index + 1);
              var params = qs.split('&');
              var master_frame_name = '';
              for (var i in params) {
                var components = params[i].split('=');
                if (components[0] == 'master_frame_name') {
                  master_frame_name = components[1];
                  break;
                }
              }
              try {
                var master_frame = parent.frames[master_frame_name];
                master_frame.ExternalNodeConnectWidget.onCommentWidgetLoaded(document);
              } catch (e) {}
            };
          </script>
        </body>
      </html>
    </iframe>
  </span>
</span>

现在加载 后,应该触发脚本函数 onPageLoad ,该函数应该将所有数据加载中。相反,我收到了一堆错误:

  1. 有臭名昭著的 不安全的 Javascript 尝试通过 URL 访问框架
  2. 当您在控制台/Firebug 中手动运行 onPageLoad() 函数(希望将内容加载到 iframe 中)时,您会得到

(在 Chrome 中) 15)

    Error: SECURITY_ERR: DOM Exception 18
      code: 18
      message: "SECURITY_ERR: DOM Exception 18"
      name: "SECURITY_ERR"
      __proto__: DOMException

(在 Firefox 7 中)

    Error: Illegal document.domain value
    document.domain = 'facebook.com';

我认为这与跨域请求有关,但对于其他人来说,他们只是收到错误,但弹出窗口仍然正确加载。 有什么想法可以让它发挥作用吗?

This is my first question asked, so if I leave out details please be a little lenient. Thanks!

I am using the Facebook Like Button plugin on my site (tried both HTML5 version and xfbml version). I have included all necessary tags and scripts for xfbml and HTML5 support. I have followed the "spec" and done a thorough amount of searching here and elsewhere to the problem:

The like button functions correctly, except that the flyout/popup that is supposed to show after clicking the button doesn't load. I mean load, not show (and yes I already checked for overflow:hidden issues per the spec). The new <span> (which includes the <iframe>) are added to the DOM immediately after the like button <span>, and they load all of the code that is supposed to be there:

<span class=" fb_edge_comment_widget fb_iframe_widget " style="top: 19px; left: 0px; z-index: 10000;">
  <span>
    <iframe id="fa02aa64d8da" class="fb_ltr" scrolling="no" name="fee6eb9f6f2768" style="border: medium none; overflow: hidden; height: 225px; width: 401px;" src="http://www.facebook.com/plugins/comment_widget_shell.php?api_key=233493930007947&locale=en_US&master_frame_name=fa12240bc73214&sdk=joey">
      <html>
        <head>
        <body onload="onPageLoad()">
          <script>
            var onPageLoad = function() {
              document.domain = 'facebook.com';
              var loc = window.location.toString();
              var index = loc.indexOf('?');
              var qs = loc.substring(index + 1);
              var params = qs.split('&');
              var master_frame_name = '';
              for (var i in params) {
                var components = params[i].split('=');
                if (components[0] == 'master_frame_name') {
                  master_frame_name = components[1];
                  break;
                }
              }
              try {
                var master_frame = parent.frames[master_frame_name];
                master_frame.ExternalNodeConnectWidget.onCommentWidgetLoaded(document);
              } catch (e) {}
            };
          </script>
        </body>
      </html>
    </iframe>
  </span>
</span>

Now after that <span> is loaded it is supposed to fire the script function onPageLoad which should load all of the data into the <iframe>. Instead I get a bunch of errors:

  1. There is the infamous Unsafe Javascript attempt to access frame with URL
  2. When you manually run the onPageLoad() function (in hopes of it loading the content into the iframe) in the console/Firebug, you get

(in Chrome 15)

    Error: SECURITY_ERR: DOM Exception 18
      code: 18
      message: "SECURITY_ERR: DOM Exception 18"
      name: "SECURITY_ERR"
      __proto__: DOMException

(in Firefox 7)

    Error: Illegal document.domain value
    document.domain = 'facebook.com';

I presume this has to do with cross-domain requests, but it seems like for other people, they just get the error but the popup still loads properly. Any ideas how to get this to work?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

宣告ˉ结束 2024-12-20 16:08:23

这是一个已知的 Facebook 错误: http://developers.facebook.com/bugs/293075054049400

基本上,如果 Facebook 用户帐户启用了安全浏览,则会出现此行为。

This is a known Facebook bug: http://developers.facebook.com/bugs/293075054049400

Basically, one gets this behavior if secure browsing is enabled on the Facebook user's account.

提笔落墨 2024-12-20 16:08:23

如果您禁用了安全浏览(默认情况下),这里是另一个可能的解决方案:
您不能在 og:url 中使用 localhost,因为 Facebook 无法浏览该页面来获取数据。因此,在开发时,请在 og:url、og:image、like/share 按钮 url 等中输入实时站点 URL。即使这可能没有帮助,但需要在实时站点上进行单击,当我部署它时效果很好。

有人知道解决方法可以使本地开发变得更容易吗?

If you have secure browsing disabled (as it is default) here is another possible solution:
You cannot use localhost in the og:url since Facebook cannot surf that page to get the data. So when developing, enter the live site URL in og:url, og:image, the like/share button url etc. Even that might not help, the click needs to be made on the live site, when I deployed it worked fine.

Anyone know a work around for this to make it easier when developing locally?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文