• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1262
  • Last Modified:

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.
0
Gary
Asked:
Gary
  • 5
  • 5
  • 2
  • +1
2 Solutions
 
GwynforWebCommented:
try this

<IFRAME name="i1" src="skdfjls" onload="alert(top.i1.document.body.scrollHeight)">
</IFRAME>
0
 
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 5
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now