简体   繁体   English

JavaScript:onclick使用iframe删除div

[英]JavaScript: onclick remove div with iframe

Hi I tried to make a div remove after clicking the facebook like button in it but Cant do it here is my code 嗨我尝试在点击其中的facebook按钮后删除div但是这里不能做我的代码

<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 ? 有没有办法在点击facebook like按钮后删除div或ifreme?

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. 您无法捕获iframe区域中的click事件,因为它由iframe本身处理,并且不会冒泡到DIV父级。 This question on SO may be helpful to you: capture click on div surrounding an iframe 关于SO的这个问题可能对您有所帮助: 捕获点击围绕iframe的div

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 ). 我可以想象一个解决方法:使用Facebook的SDK并在类似按钮上的操作上注册一个监听器(请参阅此facebook doc )。 This article "How to execute JavaScript when the Facebook Like button is clicked" gives some examples. 本文“如何在单击Facebook Like按钮时执行JavaScript”提供了一些示例。

I'm not sure about your JavaScript. 我不确定你的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. FB Like按钮上的click事件不会传播出iframe。

Here's an example: http://jsfiddle.net/kboucher/pdvdH/ 这是一个例子: http//jsfiddle.net/kboucher/pdvdH/

Facebook provides a callback function when someone clicks on the like button : https://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/ 当有人点击类似按钮时,Facebook提供回调功能: https//developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/

FB.Event.subscribe('edge.create',
    function(response) {
        alert('You liked the URL: ' + response);
    }
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM