Why do iframes don't automatically fit to inner content's scale?

Why do iframes don’t automatically fit to inner content’s scale?

Why not making them do automatically get fitted to inner contents sizes?

I believe that’s because an iframe is a separate document and to get the height of that document you would need special code in the iframe page itself that says how tall it is and passes to the parent document (your page) for laying out.

The height is simply not available to the parent document unless you have put something in place in the iframed document.

(I believe that’s why you are failing in your other threads as you are not putting the relevant js into the iframe document itself. It’s a two way process where the iframe document talks to the parent document.)


I would imagine an iframe talking with an element inside it (inside this iframe) saying:

“Dear element inside me, your natural size is 500x1000? Okay, I will resize myself to that size”.

But you say that the iframe should talk not with the element inside it but with the element outside it (the parent element).

I am confused :slight_smile:

The iframe can’t resize itself, because there is no way to refer to the iframe from the document inside the iframe.

So there needs to be a bit of code in the document that lives in the iframe to tell the document that actually contains the iframe to make the iframe bigger.

The reason browsers don’t render iframes full size is because a browser can’t know what the full size will be before the entire document inside the iframe has been rendered, meaning everything would have to wait until the document in the iframe has rendered before other things can be rendered, which leads to a bad user experience.


This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.