用户点击 Facebook Like 按钮后如何执行脚本?

发布于 2024-11-09 19:17:16 字数 578 浏览 0 评论 0原文

我正在尝试通过 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">

用户第一次单击“Like”后,我想在 DOM 内容中执行一些 Javascript。我该怎么做呢?

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/&
       layout=button_count&
       show_faces=false&
       width=50&
       action=like&
       colorscheme=light&
       height=21" 
       scrolling="no" frameborder="0" 
       style="border:none; overflow:hidden; width:50px;  
              height:21px;" 
       allowTransparency="true">

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独守阴晴ぅ圆缺 2024-11-16 19:17:16

你的意思是当你喜欢某事时你想执行一些Javascript?

为此,您可以使用 Facebook Javascript SDK,尤其是 edge.create 事件。
请参阅

  1. http://developers.facebook.com/docs/reference/javascript/ (对于一般 SDK 文档)
  2. 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>
 -->

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

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

  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)

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.

Example:

<!-- 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>
 -->
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文