The IFRAME contains Ajax and sets the IFRAME adaptive height.

Source: Internet
Author: User

-------------------------------------------------------------------

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.