![](/img/trans.png)
[英]How to trigger an event when someone clicks the Facebook Like Button? (in Google Tag Manager)
[英]How to execute script after a user clicks Like on a Facebook Like button?
我正在嘗試通過 iFrame 使用 Facebook Like 按鈕,如下所示:
<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">
用戶第一次點擊“Like”后,我想在我的 DOM 內容中執行一些 Javascript。 我將如何 go 這樣做?
你的意思是你想在喜歡的時候執行一些 Javascript ?
您可以為此使用 Facebook Javascript SDK ,尤其是edge.create
事件。
看
這也適用於 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>
-->
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.