在父页面中获取子页面的window对象和DOM
parent.html 文件
<body>
<div id=‘parentDom’>parentDom</div>
<iframe src="./children.html" id="iframeId" height="150" width="150"> </iframe>
</body>
<script type="text/javascript">
window.onload = function () {
// 子页面的window对象
var _childrenWindow = document.getElementById('iframeId').contentWindow
// 子页面的DOM
var _childrenDom=_childrenWindow.document.getElementById('childrenDom');
}
在子页面中获取父页面的window对象和DOM
children.html 文件
<body>
<div id="childrenDom">
children页面
</div>
</body>
<script type="text/javascript">
window.onload = function () {
//父页面的window对象
var _parentWindow = window.parent
//父页面的window对象
var _parentDom = parentWindow.document.getElementById('parentDom');
}
</script>