如何在用户点击后执行脚本像Facebook一样按钮? [英] How to execute script after a user clicks Like on a Facebook Like button?

查看:100
本文介绍了如何在用户点击后执行脚本像Facebook一样按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过iFrame使用Facebook Like按钮,如下所示:

I am trying to use a Facebook Like button via an iFrame, like so:

<iframe id="test" src="http://www.facebook.com/plugins/like.php? 
       href=http://yoururl.com/&amp;
       layout=button_count&amp;
       show_faces=false&amp;
       width=50&amp;
       action=like&amp;
       colorscheme=light&amp;
       height=21" 
       scrolling="no" frameborder="0" 
       style="border:none; overflow:hidden; width:50px;  
              height:21px;" 
       allowTransparency="true">

第一次用户点击Like后,我想在我的DOM中执行一些Javascript内容。

After a user clicks "Like" for the first time, I want to execute some Javascript in my DOM content. How would I go about doing this?

推荐答案

你是否希望在喜欢某事时执行一些Javascript?

You mean you want to execute some Javascript when you like something?

您可以使用Facebook Javascript SDK,特别是 edge.create 事件。

请参见

You can use the Facebook Javascript SDK for that, especially the edge.create event.
See


  1. http ://developers.facebook.com/docs/reference/javascript/ (用于一般的SDK文档)

  2. http://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/ (for event doc )

  1. http://developers.facebook.com/docs/reference/javascript/ (for general SDK doc)
  2. http://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/ (for event doc)

这也适用于IFrame版本。如果没有,你必须切换到XFBML-Like按钮。它确实适用于XFBML版本。

This should work with the IFrame-version too. If not, you have to switch to the XFBML-Like button. It definetly works with the XFBML version.

示例:

<!-- Load the SDK (or even better, load it asynchronously. See first link above -->
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
// initalize your Facebook App
  FB.init({
    appId  : 'YOUR APP ID',
    status : true, // check login status
    cookie : true, // enable cookies to allow the server to access the session
    xfbml  : true  // parse XFBML
  });
// subscribe to the event
FB.Event.subscribe('edge.create', function(response) {
  alert('you liked this');
});
FB.Event.subscribe('edge.remove', function(response) {
  alert('you unliked this');
});
</script>
<!--
    The XFBML Like Button, if the iframe version doesn't work (not 100% sure)
    <fb:like></fb:like>
 -->

这篇关于如何在用户点击后执行脚本像Facebook一样按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆