我试图让这个事件FB订阅事件被解雇(警告('hi'))但它似乎不起作用:
<!doctype html>
<html lang="en" xmlns:fb="https://www.facebook.com/2008/fbml">
<head>
<meta charset="utf-8">
<title>Facebook Like Button</title>
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function () {
FB.init({ appId: 'myappid', status: true, cookie: true, xfbml: true });
targetUrl="http://www.goal.com";
FB.Event.subscribe("xfbml.render", function () {
console.log('xfbml.render');
FB.Event.subscribe("edge.create", function (targetUrl) {
console.log('edge.create');
alert('hi');
});
FB.Event.subscribe("edge.remove", function (targetUrl) {
console.log('edge.remove');
});
});
};
(function () {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
} ());
</script>
<fb:like></fb:like>
</body>
</html>
答案 0 :(得分:0)
我注意到edge.create事件没有在localhost上触发。上传到Facebook可见的测试服务器后,它运行良好。
另外,正如Rufinus建议的那样,订阅xfbml.render回调函数之外的那些事件。
<script>
window.fbAsyncInit = function () {
FB.init({ appId: 'myappid', status: true, cookie: true, xfbml: true });
targetUrl="http://www.goal.com";
FB.Event.subscribe("xfbml.render", function () {
console.log('xfbml.render');
});
FB.Event.subscribe("edge.create", function (targetUrl) {
console.log('edge.create');
alert('hi');
});
FB.Event.subscribe("edge.remove", function (targetUrl) {
console.log('edge.remove');
});
};
(function () {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
} ());
</script>