Home  >  Article  >  Web Front-end  >  In-depth analysis of contentWindow, contentDocument_basic knowledge

In-depth analysis of contentWindow, contentDocument_basic knowledge

WBOY
WBOYOriginal
2016-05-16 17:30:111940browse

Life is always a big dye vat. When a piece of white cloth goes out, black cloth comes out. When a piece of black cloth goes out, a piece of seven-color cloth comes out.
contentWindow is compatible with various browsers and can obtain the window object of the child window.
contentDocument Firefox support, > IE8 support. The document object of the child window can be obtained.
Set the parent iframe or grandchild iframe height in the child iframe.

Copy code The code is as follows:

function showIframeH(){
var parentWin = parent.document.getElementById("test");
if(!parentWin) return false;
var sub = parentWin.contentWindow.document.getElementById("test2");
if(!sub ) return false;
var thirdHeight = sub.contentWindow.document.body.offsetHeight; //Third layer body object
sub.height = thirdHeight; //Set the height of the second layer iframe
var secondHeight = x.contentWindow.document.body.offsetHeight; //Second layer body object
x.height = secondHeight; //Set the height of the first layer iframe
//alert(secondHeight);
/ /alert('body: ' x.contentDocument.body.offsetHeight ' div:' thirdHeight);
}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn