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,286 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
3 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.
![](../../users/profiles/19068.webp)
Quentin
- 800,325
- 104
- 1,079
- 1,205
0
I think this question has been answered before
-
Sweet :) Although I can not use this (no control of the source page), it is nice to know! Thanks! – johnjohn Mar 28 '10 at 12:40
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
![](../../users/profiles/237449.webp)
futtta
- 5,577
- 2
- 19
- 32
-
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