Attach a click() event to the FaceBook 'Like' button?

前端 未结 5 1471
既然无缘
既然无缘 2020-12-25 14:27

I\'d like to do something on the page when a user clicks \'Like\'.

I thought something simple like the following would work:



        
相关标签:
5条回答
  • 2020-12-25 14:28

    One can detect 'like' and 'unlike' event of facebook like button using edge.create and edge.remove respectively.

    0 讨论(0)
  • 2020-12-25 14:37

    Facebook API doesn't allows you to subscribe to the like clicking event, but it allows you to subscribe to the like happening event (fired when the like action is completed):

    FB.Event.subscribe('edge.create', function(response) {
      // like clicked
    });
    

    see here.

    0 讨论(0)
  • 2020-12-25 14:37
    <script type="text/javascript">
        $(document).ready(function () {
    
            $('.connect_widget_like_button clearfix like_button_no_like').live('click', function () {
                alert('clicked');
            });
        });
    </script>
    
    0 讨论(0)
  • 2020-12-25 14:51

    Make a PHP (or whatever language you use) script to CURL the source from http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.MySite.Com... blahblahblah

    Put the source from facebook into your html page, you can then you can do whatever you like in JavaScript/jQuery with the code from Facebook.

    Some examples for CURL within PHP - http://www.php.net/manual/en/curl.examples.php

    0 讨论(0)
  • 2020-12-25 14:52

    You cannot use JavaScript to access elements within an iframe that does not belong to the current URL, as I guess the domain you're using is not facebook.com you won't be able to attach an event to the like button in this way.

    0 讨论(0)
提交回复
热议问题