一、同域 vs 不同域
同域,父页面可以对子页面进行改写,反之亦然
不同域,父页面没有权限改动子页面,但可以实现页面的跳转
二、 获取iframe里的内容
主要的两个API就是contentWindow,和contentDocument
iframe.contentWindow, 获取iframe的window对象
iframe.contentDocument, 获取iframe的document对象
这两个API只是DOM节点提供的方式(即getELement系列对象)
*****
另外更简单的方式是,结合Name属性,通过window提供的frames获取.
<iframe src ="/index.html" id="ifr1" name="ifr1" scrolling="yes"> <p>Your browser does not support iframes.</p> </iframe> <script type="text/javascript"> console.log(window.frames['ifr1'].window); console.dir(document.getElementById("ifr1").contentWindow); </script>
参考:
https://www.cnblogs.com/hq233/p/9849939.html
https://www.cnblogs.com/lvhw/p/7107436.html