gpt4 book ai didi

jquery - 如何在用户点击 Facebook Like 按钮上的 Like 后执行脚本?

转载 作者:行者123 更新时间:2023-11-30 05:27:50 26 4
gpt4 key购买 nike

我正在尝试通过 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 事件。

  1. > http://developers.facebook.com/docs/reference/javascript/ (一般SDK文档)
  2. > http://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/ (对于事件文档)

这也适用于 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>
-->

关于jquery - 如何在用户点击 Facebook Like 按钮上的 Like 后执行脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6125631/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com