3

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. :)

kennytm
  • 469,458
  • 94
  • 1,022
  • 977
johnjohn
  • 4,103
  • 7
  • 33
  • 43

3 Answers3

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
  • 800,325
  • 104
  • 1,079
  • 1,205
0

I think this question has been answered before

Community
  • 1
  • 1
Shuriken
  • 718
  • 5
  • 9
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,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