2013-03-21 78 views
-2

我一直在使用iframe的代码放在FB像按钮...没有捕捉FB像事件

这里是Like按钮的代码:

<iframe src="//www.facebook.com/plugins/like.php?href=https%3A%2F%2Fmadamebridal.com%2Fdev%2Fcheckout%2Fonepage%2F&amp;send=false&amp;layout=standard&amp;width=450&amp;show_faces=true&amp;font&amp;colorscheme=light&amp;action=like&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe> 

,我使用此代码来捕捉像FB事件...

下面是代码:

window.fbAsyncInit = function() { 
    (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/en_US/all.js#xfbml=1"; 
    fjs.parentNode.insertBefore(js, fjs); 
}(document, 'script', 'facebook-jssdk')); 

    // Additional initialization code here 
    FB.Event.subscribe('edge.create', 
     function(response) { 
      alert('You liked THISSS Yeaa'); 
     } 
    ); 
}; 

但是......它不工作。

+4

什么是“不工作”是什么意思?如果你甚至没有告诉我们你的问题,我们如何帮助你? – Doorknob 2013-03-21 12:36:06

+0

@ Doorknob - “不工作”意味着......当有人点击“Like”按钮时,脚本不会提示“您喜欢THISSS Yeaa” – Mohal 2013-03-21 12:46:47

+1

@Mohal - 您需要帮助我们来帮助您。 *“它不工作”*绝对不是**任何类型问题的描述。那么,你在调试方面有什么尝试?你有没有检查你的控制台?发生什么错误?你确定'fbAsyncInit'被调用吗?是否包含'all.js'?你叫'FB.init()'? – ahren 2013-03-21 12:49:27

回答

2

你的问题根本不清楚,当你去看医生时你不说,我感到痛苦,并期待他治好你。你正在加载JavaScript的SDK?

这段代码应该适用于你,除非你有其他脚本触发错误并阻止facebook sdk正常工作。

将这个代码旁边的<body>标签

<div id="fb-root"></div> 
     <script> 
      window.fbAsyncInit = function() { 
      FB.init({ 
       status  : true, // check login status 
       cookie  : true, // enable cookies to allow the server to access the session 
       xfbml  : true // parse XFBML 
      }); 

      // Additional initialization code here 
      FB.Event.subscribe('edge.create', function(response) {alert('You liked THISSS Yeaa'); }); 
      }; 


      // Load the SDK Asynchronously 
      (function(d){ 
      var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; 
      if (d.getElementById(id)) {return;} 
      js = d.createElement('script'); js.id = id; js.async = true; 
      js.src = "//connect.facebook.net/en_US/all.js"; 
      ref.parentNode.insertBefore(js, ref); 
      }(document)); 
    </script> 
+0

我知道我的问题不清楚,但问题不是代码。实际上,FB Like按钮的容器div在加载页面时隐藏。所以,JavaScript SDK没有找到“Like”按钮。 – Mohal 2013-03-22 11:44:01