2

I'm using this code (standard 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>

I need to hide the complete div (or iframe) when the user clicks on it.

I tried the onclick event but it didn't work inside iframe.

How can I do this?

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
Majklcze
  • 21
  • 1
  • 2

4 Answers4

0

You could do something like this:

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");
}
TNC
  • 5,388
  • 1
  • 26
  • 28
0

I havent done it yet. Just found a good resource http://softwareas.com/cross-domain-communication-with-iframes

maybe like that

parent.frames[1].location.href -> set to own url plus #anyanchor

so it wont be reloaded, then access the js function of main window

document.getElementById('facebookFrame').style.display = "none";
groovehunter
  • 3,050
  • 7
  • 26
  • 38
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.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
0

You can also try this solution:

FB.Event.subscribe('edge.create', function(href, widget) {
        your call back function to hide the iframe
});
Sándor Tóth
  • 743
  • 4
  • 10