Home >Web Front-end >JS Tutorial >Problem with automatic resizing of multiple iframes_form effects

Problem with automatic resizing of multiple iframes_form effects

WBOY
WBOYOriginal
2016-05-16 19:26:12949browse

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

function change_size(iframe)
{
iframe.style.height=info_content.document.body.scrollHeight 1 "px";
}
I have used this method, But the first object after the equal sign doesn't know how to dynamically display it.
For example:
function change_size(no)
{
var el_name = "iframe" no;
el = document.getElementById(el_name);
el .style.he ight=el .document.body.scrollHeight 1 "px";
                                                                                                                    // For example, the height cannot be adjusted because the el behind cannot point to the correct object
}

So I am temporarily using this Method, used once for each iframe
a.style.height = iframe_a.document.body.scrollHeight
b.style.height = iframe_b.document.body.scrollHeight

I hope you can give A simpler method. It hasn't been long since I deactivated js. The question may be a bit stupid, please forgive me.
It feels like the automatic adjustment you wrote like this will cause problems.
If the parent page is loaded but the child page is not loaded, the height of the iframe you control will definitely not be the height you want.

If your subpage and parent page are under the same domain name, I recommend a simple method for you.

Set a function in the parent page to adjust the height of a certain ifame, and then add it to the subpage This function of the parent page is called in body onload. This must wait until the sub-page is loaded and the height is set, so that it can be set to the actual height of the sub-page.

//Height setting code of the parent page, not tested

Copy code The 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 subpage
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn