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
3 Answers
Reset to default 2try 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
版权声明:本文标题:javascript - Hide div withing iframe - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744733609a2622191.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论