2

我正在使用此代码(标准 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

我怎样才能做到这一点?

4

4 回答 4

0

我还没做过。刚刚找到一个很好的资源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";
于 2011-02-22T13:46:58.513 回答
0

你可以这样做:

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");
}
于 2011-02-22T13:20:30.260 回答
0

Realistically I think that your best bet is to place another, this time transparent, div over the iframe. Set your click handler on that.

于 2011-08-25T11:01:52.550 回答
0

你也可以试试这个解决方案:

FB.Event.subscribe('edge.create', function(href, widget) {
        your call back function to hide the iframe
});
于 2011-08-25T11:08:02.567 回答