Facebook 点赞后刷新窗口

发布于 2024-12-06 04:11:36 字数 1166 浏览 0 评论 0原文

我在公司页面内创建了一个应用程序,以添加更多带有“喜欢门”的选项卡/页面,以确保用户在继续之前喜欢我们的页面。如果用户喜欢我们的页面“index2.php”被包含,则喜欢门位于“index.php”的位置,如果他们不喜欢我们,则包含“index1.php”。这一切都正常运行。

我的问题是我想在“index1.php”(如果他们不喜欢我们)页面中包含一个“喜欢”按钮。我添加了一个允许用户喜欢我们的按钮,但在单击此按钮后需要刷新,以便可以在喜欢门再次评估用户并相应地重定向。

下面的代码允许用户喜欢,但不会像我希望的那样重定向。我已经查看了 Facebook 开发人员页面上的示例,但我是 Facebook 应用程序开发新手,无法找出我的错误。任何帮助将不胜感激,希望这是足够的信息,但如果您需要更多信息,请回复。感谢您提供的任何帮助。

    <div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) {return;}
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
  fjs.parentNode.insertBefore(js, fjs);
  FB.Event.subscribe('edge.create',
    function() {
        top.window.location = 'http://www.facebook.com/pages/TAG_Communications/122751567742494?sk=app_243094502403141';
        }
    );
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-like" data-href="http://www.facebook.com/pages/TAG_Communications/122751567742494" data-send="false" data-layout="button_count" data-width="450" data-show-faces="false"></div>

I have created an app inside a company page to add more tabs/pages with a "like-gate" to ensure the user likes our page before moving forward. The like gate sits at a location say "index.php" if the user likes our page "index2.php" is included, in they do NOT like us "index1.php" is include instead. This all functions correctly.

My problem is that I would like to include a "like" button inside the "index1.php" (if they dont like us) page. I included a button allowing the user to like us, but need to refresh after this button is clicked so the user can be evaluated at the like-gate again and redirect accordingly.

The code below allows a user to like but does not redirect as I would like it to. I have look at the examples on the fb developer page but am new to fb app dev and cannot figure out my error. Any help would be appreciated, hopefully this is enough information, but reply if you need more. Thanks for any help you can provide.

    <div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) {return;}
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
  fjs.parentNode.insertBefore(js, fjs);
  FB.Event.subscribe('edge.create',
    function() {
        top.window.location = 'http://www.facebook.com/pages/TAG_Communications/122751567742494?sk=app_243094502403141';
        }
    );
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-like" data-href="http://www.facebook.com/pages/TAG_Communications/122751567742494" data-send="false" data-layout="button_count" data-width="450" data-show-faces="false"></div>

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

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

发布评论

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

评论(1

触ぅ动初心 2024-12-13 04:11:36

哇,我正在尝试做完全相同的事情,并且在您发布这个问题的同时正在搜索这个!这方面的内容不多。

我遇到了 http://www.techjam.gr /2011/web-design/execute-javascript-facebook-button-clicked/ 非常清楚地解释了单击按钮后如何运行回调脚本。我发现您已经在大部分情况下这样做了,但也许有一些部分是您遗漏或未指定的。

另外,我在尝试重定向父框架时遇到了很多麻烦,因为它会触发跨域 javascript 访问安全错误。不确定这是否是您问题的一部分。对于我自己的情况,我计划在点击时将我的 iframe 页面从 no-fan.php 之类的内容重定向到 fan.php - 如果他们是我的 fangate 代码,我不需要重新评估他们是否是粉丝单击“喜欢”按钮。

希望对您有所帮助。

更新:

在上面链接的帮助下它可以正常工作!
这就是我所做的(代码如下):
请务必使用正常的 FB.init 代码。
在按钮上方添加带有重定向代码的回调脚本。
添加 xfbml 版本的点赞按钮。
就是这样!

请注意,我实际上确实使用了 top.window.location 并将其发送到我的 fangate 评估代码。原因是,如果您只是重定向框架,它会使页面的其余部分保持原样,并且标题附近仍然有类似 facebook 的按钮。刷新整个页面可以使所有内容看起来都按其应有的方式显示,并避免混乱。

代码:

            <div id="fb-root"></div>
            <script src="http://connect.facebook.net/en_US/all.js"></script>
            <script>
                FB.init({
                    appId :'your id here',
                    status : true, // check login status
                    cookie : true, // enable cookies to allow the server to access the session
                    xfbml : true, // parse XFBML
                    channelUrl : 'full path to file', // channel.html file
                    oauth : true // enable OAuth 2.0
                });
            </script>


        <script>
            FB.Event.subscribe('edge.create', function(href, widget) {
                top.window.location = 'your tab url';
            });
        </script>

        <div id="fb-root"></div>
        <script>(function(d, s, id) {
            var js, fjs = d.getElementsByTagName(s)[0];
            if (d.getElementById(id)) {return;}
            js = d.createElement(s); js.id = id;
            js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
            fjs.parentNode.insertBefore(js, fjs);
        }(document, 'script', 'facebook-jssdk'));</script>

        <div class="fb-like"><fb:like href="your page you want to like" send="false" layout="button_count" width="200" show_faces="false"></fb:like></div>

Wow, I'm trying to do the exact same thing and was searching this at the same time you posted this question! Not much out there on this.

I came across http://www.techjam.gr/2011/web-design/execute-javascript-facebook-button-clicked/ which explains what to do to run a callback script after the button is clicked very clearly. I see you already are doing this for the most part, but maybe there are a few pieces explained that you left out or didn't specify.

Also I've run into a lot of trouble trying to redirect parent frames because it triggers a cross domain javascript access security error. Not sure if that's part of your problem. For my own case I plan to just redirect my iframe page from something like no-fan.php to fan.php on the click - I don't need to re-evaluate if they are a fan or not with my fangate code if they clicked the like button.

Hope that helps you out.

UPDATE:

Got it working with help from the link above!
Here's what I did (code below):
Be sure to use the normal FB.init code.
Add the callback script with the redirect code above the button.
Add the xfbml version of the like button.
That's it!

Note that I did actually use top.window.location and sent it to my fangate evaluation code anyways. The reason is, if you just redirect the frame it leaves the rest of the page as is , and it still has the facebook like button near the title. Refreshing the whole page gets everything looking the way it should and avoids confusion.

code:

            <div id="fb-root"></div>
            <script src="http://connect.facebook.net/en_US/all.js"></script>
            <script>
                FB.init({
                    appId :'your id here',
                    status : true, // check login status
                    cookie : true, // enable cookies to allow the server to access the session
                    xfbml : true, // parse XFBML
                    channelUrl : 'full path to file', // channel.html file
                    oauth : true // enable OAuth 2.0
                });
            </script>


        <script>
            FB.Event.subscribe('edge.create', function(href, widget) {
                top.window.location = 'your tab url';
            });
        </script>

        <div id="fb-root"></div>
        <script>(function(d, s, id) {
            var js, fjs = d.getElementsByTagName(s)[0];
            if (d.getElementById(id)) {return;}
            js = d.createElement(s); js.id = id;
            js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
            fjs.parentNode.insertBefore(js, fjs);
        }(document, 'script', 'facebook-jssdk'));</script>

        <div class="fb-like"><fb:like href="your page you want to like" send="false" layout="button_count" width="200" show_faces="false"></fb:like></div>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文