IFrame Adaptive height (1/5)

Source: Internet
Author: User
Tags setinterval

IFrame contains pages may be very large, need a very long load time, for this direct calculation of height, it is likely that the page has not finished downloading, height calculation will have problems. So it is best to compute the altitude in the onload event of the IFRAME. Also note here is that IE must use the Microsoft Event model Obj.attachevent to bind the onload event. Other browsers can also directly obj.onload = function () {}.

The 111cn.net code is as follows:
(function () {
var frame = document.getElementById ("Frame_content_parent"),
Setiframeheight = function () {
var framecontent = frame.contentwindow.document,
Frameheight = Math.max (framecontent.body.scrollheight,framecontent.documentelement.scrollheight);
Frame.height = Frameheight;
};
if (Frame.addeventlistener) {
Frame.addeventlistener ("Load", setiframeheight,false);
}else{
Frame.attachevent ("onload", setiframeheight);
}
})();

Same domain, sub page height will increase dynamically
Principle and the first case, more than one timer, has been testing the height of the word page, when the height of the sub page and the height of the IFRAME is inconsistent, reset the height of the iframe. Here you can also add a try to add a sufficient height when the page effect goes wrong.

The 111cn.net code is as follows:
(function () {
var _resetiframe = function () {
var frame = document.getElementById ("Frame_content_parent")
try {
var framecontent = frame.contentwindow.document,
Bodyheight = Math.max (framecontent.body.scrollheight,framecontent.documentelement.scrollheight);
if (bodyheight!= frame.height) {
Frame.height = Bodyheight;
}
}
catch (ex) {
frame.height = 1800;
}
}
if (Frame.addeventlistener) {
Frame.addeventlistener ("Load", function () {setinterval (_resetiframe,200);},false);
}else{
Frame.attachevent ("onload", function () {setinterval (_resetiframe,200);});
}
})();

Home 1 2 3 4 5 last

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.