关于 contentWindow, contentDocument
contentWindow 兼容各个浏览器,可取得子窗口的 window 对象。
contentDocument Firefox 支持,> ie8 的ie支持。可取得子窗口的 document 对象。
在子级iframe设置 父级 iframe ,或 孙级 iframe 高度。
1 function showIframeH(){ 2 var parentWin = parent.document.getElementById("test"); 3 if(!parentWin) return false; 4 5 var sub = parentWin.contentWindow.document.getElementById("test2"); 6 if(!sub) return false; 7 8 var thirdHeight = sub.contentWindow.document.body.offsetHeight; //第三层 body 对象 9 10 sub.height = thirdHeight; //设置第二层 iframe 的高度 11 12 var secondHeight = x.contentWindow.document.body.offsetHeight; //第二层 body 对象 13 x.height = secondHeight; //设置第一层 iframe 的高度 14 //alert(secondHeight); 15 //alert('body: ' + x.contentDocument.body.offsetHeight + ' div:' + thirdHeight); 16 }