Using JavaScript to implement IFRAME adaptive height _javascript technique

Source: Internet
Author: User

Method One:

Copy Code code as follows:

$ (window.parent.document). Find ("#ContentIframe"). Load (function () {
var main = $ (window.parent.document). Find ("#ContentIframe");
var thisheight = $ (document). Height ();
if (Thisheight < 800)
Thisheight = 800;
Main.height (Thisheight);
});

This type of writing can only be loaded when the intrinsic elements of the adaptive height, when the element changes (such as the addition of a lot of elements, height changes) can not timely change the parent form of the iframe height.

Method Two:

Copy Code code as follows:

function Setmainheight () {

var main = $ (window.parent.document). Find ("#ContentIframe");
var thisheight = $ ("body"). Height ();
if (Thisheight <) {thisheight = 800;}
Main.height (THISHEIGHT+50);

SetTimeout (Setmainheight, 2000);
}

Add a timer to poll to determine the height of the child page changes.

All of the above 2 can be an IFRAME to achieve a highly adaptive, small partners according to their own project needs, free choice Bar

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.