如何在点击时使用FB Like按钮隐藏iframe?

我正在使用此代码(标准FB Like):
<div id="like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fexample.com%2Fpage%2Fto%2Flike&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe></div>
当用户点击它时,我需要隐藏完整的
div
(或
iframe
)。 我尝试了
onclick
事件,但它在
iframe
内部无效。 我怎样才能做到这一点?     
已邀请:
你可以这样做: HTML:
<div id="like"><iframe id="facebookFrame" src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fexample.com%2Fpage%2Fto%2Flike&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe></div>
使用Javascript:
document.getElementById('facebookFrame').contentWindow.document.body.onclick = 
function() {
  // hide your iframe here or do whatever
  document.getElementById('facebookFrame').style.display = "none";
  alert("iframe was clicked");
}
    
我还没有做到。刚刚找到了一个很好的资源http://softwareas.com/cross-domain-communication-with-iframes 也许就是这样
parent.frames[1].location.href -> set to own url plus #anyanchor
所以它不会被重新加载,然后访问主窗口的js功能
document.getElementById('facebookFrame').style.display = "none";
    
实际上我认为你最好的选择是放置另一个,这次是透明的,
div
超过
iframe
。在那上设置你的点击处理程序。     
您也可以尝试这个解决方案:
FB.Event.subscribe('edge.create', function(href, widget) {
        your call back function to hide the iframe
});
    

要回复问题请先登录注册