简体   繁体   中英

Facebook-like button as an overlay to have cross-network liking?

I have a page that allows users to "like" certain elements. The liking is similar to a facebook-like, but for various reasons (such as being able to easily manipulate the data), the liking is for users of my site, and not necessarily for facebook users, and the data remains on my site. So there is a "mysite-like" button. However, I'd like it if this mysite-like button also functioned as a facebook-like button, and if a person is logged onto facebook, it would post it on their wall.

Is there a way to make a button which performs both functions? Eg perhaps by having an invisible facebook-like button, overlayed on top of the mysite-like button? Perhaps through some opacity=0 iframe? In an ideal world, clicking on one button would function as a mysite-like, and also a facebook-like, and a google+1. One button to rule them all...

The clean way to do this kind of implementation, where user interaction on a social button triggers changes on your site, is to use the callback methods.

Limitation

These callbacks work in one direction. For example:

Facebook Like button -> your custom 'like' button

OR

Google +1 button -> your custom 'like' button

As a result you will not be able to

  • trigger either of them from your custom 'like' button
  • trigger one third party button from the other

And now that you know what you can do with them, here's how to do it.

Facebook Like button callback ( from another StackOverflow post )

<script>
  FB.Event.subscribe('edge.create', function(href, widget) {
    alert('You just liked the page!');
    // this is where you would trigger your site specific logic
  });
</script>

Google +1 button callback (from the official docs )

<g:plusone callback="myCallback"></g:plusone>
<script>
function myCallback(result) {
  alert('button was just changed to state ' + result['state']);
  // this is where you would trigger your site specific logic
}
</script>

One way is to have the facebook-like button also trigger a "mysite-like" action eg via http://www.saschakimmel.com/2010/05/how-to-capture-clicks-on-the-facebook-like-button/

Is there a way to do this also with google+? You can use the callback option https://developers.google.com/+/plugins/+1button/#plusonetag-parameters but not sure how to get the userid of the user.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM