Skip to content

Instantly share code, notes, and snippets.

@faryne
Created October 31, 2011 06:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save faryne/1327005 to your computer and use it in GitHub Desktop.
Save faryne/1327005 to your computer and use it in GitHub Desktop.
Facebook Like button event binding
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Facebook Like Button Event Sample</title>
</head>
<body>
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/zh_TW/all.js#xfbml=1&appId=<FB APPID>";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-like" data-href="<Your domain>" data-send="true" data-width="450" data-show-faces="true" data-font="arial"></div>
<script type="text/javascript">
// FB.Event.subscribe 是Facebook的事件監聽function(也叫做listener)
// edge.create 代表使用者按下讚的行為時的事件
// edge.remove 代表使用者取消這個讚的行為事件
window.onload = function () { // 網頁載入完成後,才繫結這兩個事件
FB.Event.subscribe("edge.create", function(o){alert("感謝支持");});
FB.Event.subscribe("edge.remove", function(o){alert("嗯......是不是這篇文章讓你有什麼不爽的地方?");});
};
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment