2011-11-05 118 views
1

我試圖讓這個事件FB訂閱觸發的事件(警報(「你好」)),但它似乎沒有工作,雖然:點擊Facebook按鈕之後沒有觸發事件?

<!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

我會嘗試使用edge.create事件OUTSIDE的xfbml.render事件回調函數:__) – Rufinus

+0

沒有幫助:( – user603007

回答

0

我注意到沒有發射了edge.create事件在本地主機上。在上傳到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>