0

Hi I tried to make a div remove after clicking the facebook like button in it but Cant do it here is my code

<div onclick="this.parentNode.parentNode.removeChild(this.parentNode);">
<iframe id='theiframe' scrolling='no' frameBorder='0' allowTransparency='true'            src='http://www.facebook.com/widgets/like.php?href="www.facebook.com/makestream"&amp;layout=standard&amp;show_faces=true&amp;width=53&amp;action=like&amp;colorscheme=light&amp;height=80' style='width:53px;height:23px;overflow:hidden;border:0;opacity:"0.8";filter:alpha(opacity="0.8");'></iframe>
</div>

is there a way to remove the div or the ifreme after clicking the facebook like button ?

slugster
  • 49,403
  • 14
  • 95
  • 145
em.rexhepi
  • 289
  • 1
  • 5
  • 17

3 Answers3

2

You cannot capture the click event in the iframe area, since it's handled by iframe itself and won't bubble up to the DIV parent. This question on SO may be helpful to you: capture click on div surrounding an iframe

I can imagine one workaround though: take use of Facebook's SDK and register a listener on the action on like button(see this facebook doc). This article "How to execute JavaScript when the Facebook Like button is clicked" gives some examples.

Community
  • 1
  • 1
Hui Zheng
  • 10,084
  • 2
  • 35
  • 40
0

I'm not sure about your JavaScript.

Try this:

<div onclick="this.parentNode.removeChild(this);">
<!-- iframe -->
</div>

UPDATE:

I don't think this is possible.

The click event on the FB Like button will not propagate out of the iframe.

Here's an example: http://jsfiddle.net/kboucher/pdvdH/

Kevin Boucher
  • 16,426
  • 3
  • 48
  • 55
  • My guess is that the click does not propagate out of the iframe. – Kevin Boucher Jan 12 '13 at 01:51
  • i think so but is there a way to track it with any eventlistener or something i'm not good at this things but i need to do this – em.rexhepi Jan 12 '13 at 01:55
  • 1
    @user1898399 To utilize an event listener you have to have an event. The click event in this case is happening inside the iframe. Without owning the code in the iframe I see no way to alert the parent window that an event has occurred. – Kevin Boucher Jan 12 '13 at 01:56
0

Facebook provides a callback function when someone clicks on the like button : https://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/

FB.Event.subscribe('edge.create',
    function(response) {
        alert('You liked the URL: ' + response);
    }
);
Libert Piou Piou
  • 540
  • 5
  • 22