用户在Facebook“赞”按钮上单击“赞”后如何执行脚本?

问题描述

| 我试图通过iFrame使用Facebook Like按钮,如下所示:
<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\">
用户首次单击“赞”后,我想在DOM内容中执行一些Javascript。我将如何去做呢?     

解决方法

您的意思是您想在喜欢时执行一些Javascript吗? 您可以为此使用Facebook Javascript SDK,尤其是
edge.create
事件。 看到 http://developers.facebook.com/docs/reference/javascript/(适用于常规SDK文档) http://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/(针对事件doc) 这也应该适用于IFrame版本。如果不是,则必须切换到XFBML-Like按钮。它绝对适用于XFBML版本。 例:
<!-- 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>
 -->
    

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...