2

I have been googling for a while, and found some similar topics on iframe resizing,
and actually I learned a lot from those, such as
1. Resize iframe to content with Jquery
2. Adding Dynamic Contents to IFrames
thanks for those people who contributed to answer those questions.
but I still got some questions which is not resolved,
so do you guys have any idea how to resize iframe when content's getting smaller?
In my case, I was trying to get content height either using
document.documentElement.scrollHeight or document.body.scrollHeight, but it won't work.
I guess it's hard to get the correct content height from outside, should we need a height
parameter to be passed to the resize function?

Community
  • 1
  • 1
LeoYuan 袁力皓
  • 2,270
  • 1
  • 15
  • 16

2 Answers2

1

You need to use document.body.offsetHeight.

David Bradshaw
  • 11,859
  • 3
  • 41
  • 70
0

Whit testing on different sites and browsers, I finally got the best results for the height whit this code:

var height = document.documentElement.offsetHeight;
if(document.all) height = Number(document.body.clientHeight) + Number(document.body.bottomMargin) + Number(document.body.topMargin); // IE v <= 10
Den
  • 547
  • 1
  • 6
  • 15