Howto: handling IFRAME adaptive height in IE8

Source: Internet
Author: User

Old-fashioned questions,The overwhelming solution on the network, as well as the copy-and-transfer "blog", mainly describes a specific problem in IE8 today.

 Function  Autosetframeheight (name ){  Try  {  VaR  IFRAME;  If (! Name) Return  ; IFRAME = Document. getelementbyid (name );  If (IFRAME. contentdocument) $ ( "#" + Name). Height (IFRAME. contentdocument. height + "PX" );  Else  $ ( "#" + Name).height(document.frames?name=.doc ument. Body. scrollheight + "PX" );}  Catch  (E ){  //  Alert (E. Message );  }} 

User response todayIE8Next pop-up window(IFRAMEEmbedded small page)Incomplete display,After testing,IFRAME. contentdocument. HeightInIE8 is invalid in IE6-7, chrome, firefox3 ~ 4 lower

ChangeIFRAME. contentdocument. Body. offsetheightLater, in IE6-8, chrome, firefox3 ~ 4. The test passes.

ExampleCodeRunning in real projects,HoweverIFRAMEThe content on the target page is relatively simple.,Therefore, it is not tested.IFRAMEThe target page contains the absolute positioning layer./Fold,And the situation that includes the float layer,

And someArticleMentioned"NonIEThe browser will be too tall to scale back"..Please note.

Additional information:(You are requested to manually upload the original content of the certificate, which is accepted by the certificate)

  1. http://www.cnblogs.com/yuhe7919/archive/2009/11/04/iframe.html
  2. http://blog.pchome.net/article/194139.html

    example of Token Generation mentioned in this article , I suggest you stop using it, if the first line takes the height of the Token because of the compatibility issue of the receiver, the token is completely invalid. in addition, there is no intention of using two highly comparable methods, and some of them have a poor sense.

    try {

    v ar bheight = iframe.content?#doc ument. body. scrollheight;
    var dheight = iframe.content##document.doc umentelement. scrollheight;

    }catch (Ex) {}

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.