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.
LVL 58
GaryAsked:
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.

GwynforWebCommented:
try this

<IFRAME name="i1" src="skdfjls" onload="alert(top.i1.document.body.scrollHeight)">
</IFRAME>
0

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
GaryAuthor Commented:
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.
0
GwynforWebCommented:
you can only get the scroll height if the page has loaded and it is from the same domain
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

GaryAuthor Commented:
Ahh just discovered its setting the maximum height to the visible browser window height - can I get round this?
0
ZvonkoSystems architectCommented:
Do it like this:

onload="this.style.height=window.frames.iframeName.document.body.scrollHeight"


0
GwynforWebCommented:
<IFRAME name="i1" src="skdfjls" onload="document.getElementById('i1').height=top.i1.document.body.scrollHeight"></IFRAME>
0
GaryAuthor Commented:
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
0
GaryAuthor Commented:
Excellent Zvonko, works like a charm :o)
0
GwynforWebCommented:
if it not from your domain there is nothing you can do
0
ZvonkoSystems architectCommented:
Thanks :-)
0
GaryAuthor Commented:
Thanks also to GwynforWeb :o)
0
GwynforWebCommented:
Thx :-)
0
IMacNeillCommented:
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...
0
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
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.