【问题标题】:Redirect after a user clicked a facebook like button用户点击 facebook like 按钮后重定向
【发布时间】:2011-08-03 09:31:44
【问题描述】:

我有一个带有 iframe 应用程序的 facebook 选项卡,并且在该选项卡内有一个 facebook like 按钮,具有第二个功能来喜欢 facebook 页面。它是一个普通的 Facebook 按钮 iframe。

当用户点击按钮时是否有可能重定向用户?我尝试了以下代码:

<div id="fb-root"></div>
<script type="text/javascript">
    window.fbAsyncInit = function() {
        FB.init({appId: '<my app id>', status: true, cookie: true, xfbml: true});
        FB.Canvas.setSize({ width: 520, height: 1500 });
        FB.Event.subscribe('edge.create',
            function(response) {
                alert('like!');
            }
        );
    };

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

但这不起作用。有没有办法或者我做错了什么?

【问题讨论】:

标签: javascript facebook facebook-like


【解决方案1】:

我刚刚测试了以下代码,它按预期工作

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<head></head>
<body>
<div id="fb-root"></div>

<fb:like href="http://yoururlto.like" send="false" width="450" show_faces="false" font=""></fb:like>

<script type="text/javascript">
    window.fbAsyncInit = function() {
        FB.init({appId: 'YOUR_APP_ID', status: true, cookie: true, xfbml: true});
        FB.Canvas.setSize({ width: 520, height: 1500 });
        FB.Event.subscribe('edge.create',
            function(response) {
                alert('like!');
                // put redirect code here eg
                window.location = "http://www.mysite.com/redirected.html"; 
            }
        );
    };

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

它与您自己的页面相比如何?

【讨论】:

  • 点赞按钮不是在 fbml 中实现的,而是作为 iframe 实现的。
  • 对不起。如果必须使用 iFrame,则不会触发 create.edge 事件。
  • FB-Tags 只能在 FBML-Tabs 中工作,还是 fb javascript 库用 html 替换它们?
  • Facebook JavaScript 将渲染 XFBML 以用于 iFrame 和网站。试试我上面的代码示例。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-06
相关资源
最近更新 更多