最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Redirect after a user clicked a facebook like button - Stack Overflow

matteradmin4PV0评论

I have a facebook tab with an iframe application and within that tab there is a facebook like button to have a second capability to like the facebook page. It is an ordinary facebook like button iframe.

Is there a possibility to redirect the user when it clicks the button? I tried it the following code:

<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/en_US/all.js';
            document.getElementById('fb-root').appendChild(e);
    }());
</script>

But this doesn't work. Is there a way or am I doing something wrong?

I have a facebook tab with an iframe application and within that tab there is a facebook like button to have a second capability to like the facebook page. It is an ordinary facebook like button iframe.

Is there a possibility to redirect the user when it clicks the button? I tried it the following code:

<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/en_US/all.js';
            document.getElementById('fb-root').appendChild(e);
    }());
</script>

But this doesn't work. Is there a way or am I doing something wrong?

Share Improve this question edited Aug 3, 2011 at 17:07 stofl asked Aug 3, 2011 at 9:31 stoflstofl 2,9827 gold badges37 silver badges49 bronze badges 2
  • Is the like button functioning properly on its own? – jBit Commented Aug 3, 2011 at 9:52
  • possible duplicate of How can I redirect once facebook like button is clicked? – ifaour Commented Aug 3, 2011 at 11:02
Add a ment  | 

1 Answer 1

Reset to default 1

I just tested the following code and it works as expected

<html xmlns="http://www.w3/1999/xhtml" xmlns:fb="http://www.facebook./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./redirected.html"; 
            }
        );
    };

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

How does it pare to your own page?

Post a comment

comment list (0)

  1. No comments so far