Javascript 像单击一样隐藏Facebook

Javascript 像单击一样隐藏Facebook,javascript,iframe,onclick,Javascript,Iframe,Onclick,对于我的网站,我想在我的网站上添加一个类似Facebook的内容 以下是我使用的代码: document.write('<iframe id="like-box" src="http://www.facebook.com/plugins/like.php?href='+ like_url +'&amp;layout=button_count&amp;show_faces=true&amp;width=450&amp;action=like&amp;c

对于我的网站,我想在我的网站上添加一个类似Facebook的内容

以下是我使用的代码:

document.write('<iframe id="like-box" src="http://www.facebook.com/plugins/like.php?href='+ like_url +'&amp;layout=button_count&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:60px; height:80px;" allowTransparency="true"></iframe>');

var popupDiv = document.getElementById('like-box');
popupDiv.onclick = function(e){
    if (!e) e = window.event;
    alert("Like button will be removed");
    document.removeChild(popupDiv);
};
但它也不起作用我试图触发点击窗口,但得到了相同的结果

你能帮我解决吗

编辑:

我会尽量用更好的方式解释。 我想在主文档的iframe内部或上方检测单击事件。我的意思是: 我在我的网站上。我点击facebook,点击被我的index.html页面触发,几秒钟后我删除了iframe。但类似的情况已经被FB抓住了。 这基本上就是我想做的。我尝试过许多在单击iframe时触发函数的代码,但都没有成功。 例如:

onload="this.contentWindow.document.onclick=function(){alert(\'test\')}"
根本不起作用

编辑2:
这看起来是一个严重的问题,因为如果我在我的窗口上使用onclick函数(例如
window.onclick=function(e){…};
当我在iframe中单击时,它不会被触发。有什么想法吗?

而不是
document.removeChild(popupDiv)
尝试一下:

popupDiv.parentNode.removeChild(popupDiv);

IIRC,您只能使用其父节点而不是文档本身删除节点。

尝试
document.getElementById(popupDiv.innerHTML=“”;
从正文中删除:
document.body.removeChild(popupDiv);

最后我找到了这样做的方法(至少是第一次单击)。如果有人需要代码,这里是:

var inIframe = false;
function checkClick()
{
    if (document.activeElement && document.activeElement === document.getElementById("iframe_id_goes_here"))
    {
        if (inIframe == false)
        {
            console.log("Clicked");
            inIframe = true;
        }
    }
    else inIframe = false;
}
setInterval(checkClick, 200);

感谢那些试图帮助我的人。

谢谢,但问题不是要删除,而是要触发clickNope它不起作用。有没有办法使用
designMode=“on”;
或其他方法?
var inIframe = false;
function checkClick()
{
    if (document.activeElement && document.activeElement === document.getElementById("iframe_id_goes_here"))
    {
        if (inIframe == false)
        {
            console.log("Clicked");
            inIframe = true;
        }
    }
    else inIframe = false;
}
setInterval(checkClick, 200);