-------------------------------------------------------------------
Http://www.jb51.net/article/15780.htm
Http://www.jb51.net/article/48936.htm
Http://bestchenwu.iteye.com/blog/1231956
Add this JS outside IFRAME. either of the following can be
------------ 1 ----------------------------
Function iframeheight (){
VaR IFM = Document. getelementbyid ("cateframe ");
VaR subweb = Document. frames? Document. Frames ["cateframe" 2.16.doc ument: IFM. contentdocument;
If (IFM! = NULL & subweb! = NULL ){
IFM. Height = subweb. Body. scrollheight;
}
}
----------- 2 -----------------------
Function setwinheight (OBJ ){
VaR win = OBJ;
If (document. getelementbyid ){
If (WIN &&! Window. Opera ){
If (win. contentdocument & Win. contentdocument. Body. offsetheight)
Win. Height = win. contentdocument. Body. offsetheight;
Else if (win. Document & Win. Document. Body. scrollheight)
Win. Height = win. Document. Body. scrollheight;
}
}
}
------ Modify IFRAME --------
Onload method, you can write iframeheight () or Javascript: setwinheight (this)
<IFRAME id = "cateframe" name = "cateframe" width = "100%" frameborder = "0" scrolling = "no"
Marginwidth = "0" marginheight = "0" src = "Welcome. aspx" onLoad = "iframeheight ()">
<% -- Javascript: setwinheight (this) -- %>
</Iframe>
---------------- The following is the case that AJAX is used -------------------
Add this JS after the body in the IFRAME page and set the IFRAME height again
<SCRIPT type = "text/JavaScript">
VaR iframeloaded = function (IFRAME ){
If (IFRAME. SRC. length> 0 ){
If (! IFRAME. readystate | IFRAME. readystate = "complete "){
VaR bheight = iframe.content20.doc ument. Body. scrollheight;
VaR dheight = iframe.content?document.doc umentelement. scrollheight;
VaR Height = math. Max (bheight, dheight );
IFRAME. Height = height;
}
}
}
// Reset the IFRAME height when paging; after modification: IFRAME. Name = IFRAME. ID
VaR resetiframeheight = function (){
// Try {
VaR oiframe = parent.doc ument. getelementbyid (window. Name );
// Oiframe. Height = 80;
Iframeloaded (oiframe );
//}
// Catch (ERR ){
// Try {
// Parent.doc ument. getelementbyid (window. Name). Height = 500;
//} Catch (err2 ){}
//}
}
// Resetiframeheight ();
VaR sendcount = 0;
VaR completecount = 0;
// Add Ajax global event processing.
$ (Document). ajaxstart (function (a, B, c ){
}). Ajaxsend (function (E, xhr, opts ){
Sendcount ++;
}). Ajaxerror (function (E, xhr, opts ){
}). Ajaxsuccess (function (E, xhr, opts ){
}). Ajaxcomplete (function (E, xhr, opts ){
Completecount ++;
Resetiframeheight ();
}). Ajaxstop (function (){
});
</SCRIPT>
The IFRAME contains Ajax and sets the IFRAME adaptive height.