为什么我的 Facebook Like 按钮会出现此错误?

发布于 12-02 00:00 字数 1112 浏览 0 评论 0原文

Uncaught ReferenceError: _onloadHook is not defined

为什么?我的代码如下:

<!DOCTYPE html  xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<html>
<head>
<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script>
    <script type="text/javascript">
    //Initialize facebook
        FB.init({
            appId  : '12345',
            status : true, // check login status
            cookie : true, // enable cookies to allow the server to access the session
            xfbml  : true, // parse XFBML
            channelUrl : 'http://www.abc.com/channel.html', // channel.html file
        });
    </script>
</head>

<body>
<div id="fb-root"></div>
<fb:send href="http://abc.com/blah" font="lucida grande" ref="codes_popup"></fb:send>
<fb:send href="http://abc.com/blah" font="lucida grande" ref="codes_popup"></fb:send>
</body>
</html>

编辑:当我有多个时,就会发生这种情况。当我只有一个“发送”按钮时,错误不存在。

对于每个额外的“发送”按钮,都会发生错误。

Uncaught ReferenceError: _onloadHook is not defined

Why? My code is below:

<!DOCTYPE html  xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<html>
<head>
<script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script>
    <script type="text/javascript">
    //Initialize facebook
        FB.init({
            appId  : '12345',
            status : true, // check login status
            cookie : true, // enable cookies to allow the server to access the session
            xfbml  : true, // parse XFBML
            channelUrl : 'http://www.abc.com/channel.html', // channel.html file
        });
    </script>
</head>

<body>
<div id="fb-root"></div>
<fb:send href="http://abc.com/blah" font="lucida grande" ref="codes_popup"></fb:send>
<fb:send href="http://abc.com/blah" font="lucida grande" ref="codes_popup"></fb:send>
</body>
</html>

Edit: When I have multiple this will happen. When I only have one "send" button , the error is not there.

For every extra "Send" button, the error occurs.

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

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

发布评论

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

评论(4

那伤。2024-12-09 00:00:15

这是 Facebook 平台中的一个错误;它已被报告为 bug #20041

This is a bug in the Facebook Platform; it has already been reported as bug #20041.

这样的小城市2024-12-09 00:00:15

将 Facebook JS 库和 JS 代码脚本放置在 fb-root div 下

<!DOCTYPE html  xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<html>
<head>

</head>

<body>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script type="text/javascript">
//Initialize facebook
    FB.init({
        appId  : 'XXX',
        status : true, // check login status
        cookie : true, // enable cookies to allow the server to access the session
        xfbml  : true, // parse XFBML
        channelUrl : 'http://www.abc.com/channel.html', // channel.html file
    });
</script>
<fb:send href="http://abc.com/blah" font="lucida grande" ref="codes_popup"></fb:send>
</body>
</html>

Place the Facebook JS library and JS code scripts under the fb-root div:

<!DOCTYPE html  xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<html>
<head>

</head>

<body>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script type="text/javascript">
//Initialize facebook
    FB.init({
        appId  : 'XXX',
        status : true, // check login status
        cookie : true, // enable cookies to allow the server to access the session
        xfbml  : true, // parse XFBML
        channelUrl : 'http://www.abc.com/channel.html', // channel.html file
    });
</script>
<fb:send href="http://abc.com/blah" font="lucida grande" ref="codes_popup"></fb:send>
</body>
</html>
迷爱2024-12-09 00:00:15

我今天遇到了完全相同的错误。

正如 ifaour 提到的,FB 文档说您需要将 FB

I have been getting the exact same error today.

As ifaour mentions, the FB documentation says that you need to place the FB <script> tags under the <div id="fb-root"></div>. However, in his example and in the FB documentation, they put the scripts directly under the <div id="fb-root"></div>. I was doing that and still getting the error the OP mentions. I was finally able to solve the problem by moving the FB <script> tags to the very bottom of the page, right before the closing </body> tag. I believe what was happening is that some of my other scripts were interfering with the loading of the FB scripts. Hope that helps.

太阳公公是暖光2024-12-09 00:00:15

您应该使用升级后的异步方法调用 facebook javascript。这将确保加载整个 DOM,以便 fb:root 已经在页面上。

http://developers.facebook.com/docs/reference/javascript/FB。 init/

<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId  : 'YOUR APP ID',
      status : true, // check login status
      cookie : true, // enable cookies to allow the server to access the session
      xfbml  : true,  // parse XFBML
      channelUrl  : 'http://www.yourdomain.com/channel.html', // Custom Channel URL
      oauth : true //enables OAuth 2.0
    });
  };

  (function() {
    var e = document.createElement('script');
    e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
    e.async = true;
    document.getElementById('fb-root').appendChild(e);
  }());
</script>

同样至关重要的是添加对 OAuth 2.0 的支持 http://developers.facebook.com/blog/post/525/

oauth : true

从 10 月 1 日起,如果您不这样做,您的应用程序将停止正常运行。

You should call the facebook javascript using the upgraded async method. This will make sure that the whole DOM is loaded so that the fb:root is already on the page.

http://developers.facebook.com/docs/reference/javascript/FB.init/

<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId  : 'YOUR APP ID',
      status : true, // check login status
      cookie : true, // enable cookies to allow the server to access the session
      xfbml  : true,  // parse XFBML
      channelUrl  : 'http://www.yourdomain.com/channel.html', // Custom Channel URL
      oauth : true //enables OAuth 2.0
    });
  };

  (function() {
    var e = document.createElement('script');
    e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
    e.async = true;
    document.getElementById('fb-root').appendChild(e);
  }());
</script>

Also critically important is to add support for OAuth 2.0 http://developers.facebook.com/blog/post/525/

oauth : true

As of Oct 1 if you don't have that your apps will stop working properly.

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