發現比較好用的iframe父子頁面操作方法,記錄一下
1.父頁面 test.html
<iframe id="iframe1" src="iframe.html"></iframe>
獲取iframe var oframe = document.getElementById("main")
獲取子頁面 var child = oframe.contentWindow.document
獲取子頁面元素 var test = child.getElementById("test")
獲取子頁面高度 var childh = child .body.offsetHeight
獲取子頁面高度
2.子頁面 iframe.html
<div id="test"></div>
獲取父頁面 var parent = window.parent.document
注意:需要把代碼放在服務器端,才能兼容google瀏覽器