admin管理员组

文章数量:1391929

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.

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".

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

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.

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".

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

Share Improve this question edited Nov 22, 2010 at 19:03 PleaseStand 32.1k7 gold badges70 silver badges96 bronze badges asked Nov 22, 2010 at 18:43 out_siderout_sider 131 gold badge1 silver badge3 bronze badges 2
  • Your example appears to be inplete, the iframe is empty. – DwB Commented Nov 22, 2010 at 18:44
  • @dwb: It's not necessarily empty; that's determined by what's at the src URL. – PleaseStand Commented Nov 22, 2010 at 18:47
Add a ment  | 

3 Answers 3

Reset to default 2

try frame.contentWindow.document.getElementById or frame.contentDocument.getElementById

.style.visibility = "hidden";

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 inside the 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.

本文标签: javascriptHide div withing iframeStack Overflow