SoFunction
Updated on 2025-02-28

The problem of automatic resizing of multiple iframes

I have multiple iframes on a page, and the src of each iframe is different and the height is also different.
How to use a function to automatically adjust the height of all iframes in this page?

function change_size(iframe)
{
    =info_content.+1+"px";
}
I've used this method, but I don't know how the first object after the equal sign should be displayed dynamically.
for example:
function change_size(no)
{
                var el_name = "iframe"+no;
                el = (el_name);
    el .=+1+"px";
//For example, the height cannot be adjusted in reality, because the subsequent el cannot point to the correct object
}

So I'm using this method for the time being, and use it once for each iframe.
 = iframe_a.
 = iframe_b.

Hope you can give a simpler method. I didn't have long since I solved js. The problem may be a bit stupid, please forgive me.
I feel that the automatic adjustment you write like this will cause problems.
If the parent page is loaded and the child page is not loaded, the iframe height you control will definitely not be the height you think.

If your child and parent page are in the same domain name, it is recommended to you a simple method.

Set a function in the parent page to adjust the height of a certain ifame, and then call the function of the parent page in the body onload of the child page. This is definitely the set height when the child page is loaded, so that it can be set to the actual height of the child page.

//The setting height code of the parent page, not tested
Copy the codeThe code is as follows:

function setParentFrameHeight(frameid,height){
    var frame= (frameid);
= height;//The actual height can be obtained in the body of the subpage
}