Adjusting the height of an IFRAME according to its content
18 comments. Current rating: (4 votes). Leave comments and/ or rate it.
Question:On my page I display search results in an IFRAME. Sometimes there's only 5 rows of data, sometimes it can be 2000. I need to have the IFRAME size adjust to the number of elements. I was working with a construct like
iframe_1.height = 30 + 16 * (number_of_rows)
but this estimating formula relies on a certain font size. And it looks really wrong in Netscape or Opera.
Answer:Why estimate if you can make an exact calculation of the document height? Take the code below which will work on Internet Explorer and various Netscape versions.