跨域修改iframe(框架)中的文字内容

html代码:

<body style='overflow:-Scroll;overflow-y:hidden'>
    <iframe id = "content" frameborder=no  border=0  marginwidth=0  marginheight=0  width='100%' height='100%' allowfullscreen='true' src="replace.php?http://vip.ikoori.com/index.zul"></iframe>
</body>
<script type="text/javascript">
    window.οnlοad=function(){
         console.log('执行');
    }
</script>

需求:把左上角的“办件公示”隐藏掉,class="tips",并且在window.οnlοad打印不了,是怎么回事呢?

clipboard.png

阅读 4k
2 个回答

你这个父页面获取iframe子页面的内容涉及到跨域问题:document.getElementById('content').contentDocument.getElementsByClassName('tips').hide();

可以通过获取iframe元素的contentWindowcontentDocument属性来获取iframe的window和document进行对iframe内部的操作

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题