Is there a way to set the height of the iframe to be the same as the height of its source?
I am trying to
a) Avoid scrollbars and
b) Avoid using fixed height in px
Thank you. :)
Asked
Active
Viewed 1,294 times
3
-
The "height of its source" meaning the height of the page displayed inside the frame? – Jørn Schou-Rode Mar 28 '10 at 09:07
-
Yes, that is the meaning indeed. Also, the source page is on a different domain. – johnjohn Mar 28 '10 at 10:45
2 Answers
1
Since the source page is on a different domain — no.
The only way to adjust its size based on the content is to measure the rendered size of the content using JavaScript, and the Same Origin Policy will prevent this.

Quentin
- 914,110
- 126
- 1,211
- 1,335
0
if i understand correctly you have control over the iframe-content? in that case i wrote a javascript thingie (squeezeFrame.js) a couple of weeks ago, that can do just what you need.
essentially it uses;
- clientWidth (and optionally -Height) to get the size of the "viewport"
- scrollWidth (again optionally -Height) to get the size of the entire (iframed) page
- zoom (and -moz-transform: scale for firefox) to zoom in/out
you can see a couple of demo's of squeezeFrame.js in action here

futtta
- 5,917
- 2
- 21
- 33
-
No, no control over the content inside the iframe, unfortunately. Thank you for your contribution, it could be useful in other situations than mine, and it is good to know! – johnjohn Apr 05 '10 at 16:09