javascript 使用 iframe 隐藏 div

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4249005/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 10:46:59  来源:igfitidea点击:

Hide div withing iframe

javascriptiframegoogle-docs

提问by out_sider

I have an iframe and I'd like to hide a div whithin it, so bascily people can't for example sign out in the iframe.

我有一个 iframe,我想在它里面隐藏一个 div,所以基本上人们不能例如在 iframe 中注销。

What I did was :

我所做的是:

<script type="text/javascript">
function changeCSS(){
frame = document.getElementById("myIframe");
frame.document.getElementById("guser").style.display='none';
}
</script>

<iframe onload="javascript:changeCSS()" id="myIframe" src="{$docUrl}" width="800px" height="600px"></iframe>

But I can't get it to hide the div "guser".

但我无法让它隐藏 div“guser”。

If anyone could help I'd be very much appreciated.

如果有人可以提供帮助,我将不胜感激。

回答by meder omuraliev

try frame.contentWindow.document.getElementByIdor frame.contentDocument.getElementById

尝试frame.contentWindow.document.getElementByIdframe.contentDocument.getElementById

回答by Lockhead

.style.visibility = "hidden";

.style.visibility = "隐藏";

回答by PleaseStand

Different hostname or domain?If you don't have control over the framed page, there's nothing you can easily do.If you do have control over the framed page, try checking insidethe frame whether the page is framed or not (this is based on a well-known frame-busting code):

不同的主机名或域?如果您无法控制框架页面,则无法轻松执行任何操作。如果您确实可以控制框架页面,请尝试框架内部检查页面是否已框架(这是基于众所周知的框架破坏代码):

function changeCSS() {
    document.getElementById("guser").style.display = 'none';
}

if(top != self) {
    if(window.addEventListener) {
        window.addEventListener('load', changeCSS, false);
    } else {
        window.attachEvent('onload', changeCSS);
    }
}

Edit: Now that you mention Google Docs, I believe the above code won't work.

编辑:既然你提到了 Google Docs,我相信上面的代码是行不通的。