resizing an iFrame depending on cross-domain content


I would like to resize an iFrame (height) depending on content (from another domain).  

I know it's possible as the website is doing it (just have a look at this URL:

The bottom is an iFrame and the height is adjusting to the content height.

How he's doing it?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Michel PlungjanIT ExpertCommented:
Where do you see it is resizing?

It has a width of 100% if that is what you mean

<iframe width="100%" height="1000px" frameborder="0" style="background-color: rgb(255, 255, 255); height: 566px;" src="..." id="globpage"></iframe>

Try the snippet:

<iframe id="my_iframe" src="MY_IFRAME_URL" width="100%" scrolling="no" onload="checkHeight();"></iframe>

<script type="text/javascript">

   function checkHeight() {
      h = document.getElementById('my_iframe').contentDocument.body.scrollHeight;
      document.getElementById('my_iframe').style.height = h;


Open in new window

Michel PlungjanIT ExpertCommented:
I am pretty sure that will give you an access denied in most browsers
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Yes - if the iframe url is external to your site, in which case you're stuffed. (soz - just saw that in the question - url from another domain).

I'm not sure there is a way to do it using an iframe...

jeff0191Author Commented:
If you go on the home page and click on any article, you'll see that the iFrame is effectively resizing depending on content.  And this content is on an external website.  

Also, when I looked in the js file (site.js) there's a function adapt() where I can see:

$('globpage').style.height = (document.viewport.getHeight()-marginsize)+'px';

Not sure what this doing but this function is called in the body onload event.  
Michel PlungjanIT ExpertCommented:

I searched for viewport and found prototype calls and this (scroll down for the comment)
jeff0191Author Commented:
That's a cool script mplungjan, but that's not doing what I want (it does an iFrame act like a lightbox but not resizing depending on iFrame content).  But i'll definitely bookmark this page as it could be cool to use it some time :)
Michel PlungjanIT ExpertCommented:
so globpage is the ID of the iFrame
document.viewport must be the main document and not the iframe document.
So it is as far as I can see NOT resizing to the iframe content but resizing the iframe to the document containing the iframe
jeff0191Author Commented:
Hey guys, I think I've finally found a solution.

Just look at this page:

it's resizing depending on the content (just change the param in the URL to see it working).

I'll just explore what he did.  

Thanks for your help!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.