Multiple iframe auto-resize Problems

Source: Internet
Author: User

One page has multiple iframe, and each iframe has different src values and different heights.
How can I use a function to automatically adjust the height of all iframe on this page?

Function change_size (iframe)
{
Iframe.style.height=info_content.doc ument. body. scrollHeight + 1 + "px ";
}
I used this method, but the first object after the equal sign does not know how to dynamically display it.
For example:
Function change_size (no)
{
Var el_name = "iframe" + no;
El = document. getElementById (el_name );
El .style.heightw.el.doc ument. body. scrollHeight + 1 + "px ";
// For example, the height cannot be adjusted because the later el cannot point to the correct object.
}

So now I use this method for the moment.
A. style. height = iframe_a.document.body.scrollHeight
B. style. height = iframe_ B .document.body.scrollHeight

I hope you can give me a simpler method. It may not be long before I release js. The problem may be a bit silly. Please forgive me.
It seems that the automatic adjustment you write will cause problems.
If the parent page is loaded and the Child page is not loaded, the iframe height you control will not be what you think.

If your child and parent pages are under the same domain name, we recommend a simple method.

Set a function on the parent page to adjust the height of an ifame, and then call the function on the parent page in the body onload of the child page. in this way, the actual height of the sub-page can be set after the sub-page is loaded.

// Set height code of the parent page, not testedCopy codeThe Code is as follows:
Function setParentFrameHeight (frameid, height ){
Var frame = document. getElementById (frameid );
Frame. style. height = height; // The actual height can be obtained in the body of the Child page.
}

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.