Reprinted: http://wenwen.soso.com/z/q229512802.htm
// Iframe highly adaptive
Function IFrameReSize (iframename ){
Var pTar = document. getElementById (iframename );
If (pTar) {// ff
If (pTar. contentDocument & pTar. contentDocument. body. offsetHeight ){
PTar. height = pTar. contentDocument. body. offsetHeight;
} // Ie
Else if (pTar. Document & pTar. Document. body. scrollHeight ){
PTar. height = pTar. Document. body. scrollHeight;
}
}
}
// Iframe adaptive width
Function IFrameReSizeWidth (iframename ){
Var pTar = document. getElementById (iframename );
If (pTar) {// ff
If (pTar. contentDocument & pTar. contentDocument. body. offsetWidth ){
PTar. width = pTar. contentDocument. body. offsetWidth;
} // Ie
Else if (pTar. Document & pTar. Document. body. scrollWidth ){
PTar. width = pTar. Document. body. scrollWidth;
}
}
}
The usage is as follows:
<Iframe src = "Main. aspx "scrolling =" no "frameborder =" 0 "height =" 100% "id =" mainFrame "width =" 100% "onload = 'iframeresize (" mainFrame "); IFrameReSizeWidth ("mainFrame"); '> </iframe>