Link to home
Start Free TrialLog in
Avatar of Gary
GaryFlag for Ireland

asked on

iFrame Height

Is it possible to get the height of content in an iFrame i.e. the frame may be set to 300px high but the content is 600px 'high'.  I want to know the 'height' of the content.
ASKER CERTIFIED SOLUTION
Avatar of GwynforWeb
GwynforWeb
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Gary

ASKER

Beat me to it, just found the answer.  But I have another problem, I'm trying to set the height of the iframe dynamically to be the height of whatever content is in it.  And I'm using
onload="this.style.height=document.body.scrollHeight"

But sometimes it doesnt stretch large enough and other times I get lots of blank space at the bottom.  What am I doing wrong.
you can only get the scroll height if the page has loaded and it is from the same domain
Avatar of Gary

ASKER

Ahh just discovered its setting the maximum height to the visible browser window height - can I get round this?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
<IFRAME name="i1" src="skdfjls" onload="document.getElementById('i1').height=top.i1.document.body.scrollHeight"></IFRAME>
Avatar of Gary

ASKER

The source is a page on my domain but may contain images from another domain.
And its setting the height to the height of the browser even when the content shouldnt make it that high
Avatar of Gary

ASKER

Excellent Zvonko, works like a charm :o)
if it not from your domain there is nothing you can do
Thanks :-)
Avatar of Gary

ASKER

Thanks also to GwynforWeb :o)
Thx :-)
Avatar of IMacNeill
IMacNeill

Thank you! My subscription to this site just paid off -- this solution solved my problem of having content dynamically loaded into an iframe, but couldn't figure out how to vertically stretch the iframe on content load.

Very nice...