From 59ee9d3f8fbb867c3f04e15b3657079e0b92e62b Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Thu, 21 Oct 2010 00:33:48 -0600 Subject: [PATCH] Bug #9297: More hacks to fix IFRAME height for troublesome HTML data --- imp/js/imp.js | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/imp/js/imp.js b/imp/js/imp.js index 665b5047c..d6eb6d833 100644 --- a/imp/js/imp.js +++ b/imp/js/imp.js @@ -88,16 +88,27 @@ document.observe('dom:loaded', function() { this.iframeResize(id); }; - IMP.iframeResize = function(id, delay) + IMP.iframeResize = function(id) { + var val, + i = 0; + if (id = $(id)) { - id.setStyle({ height: Math.max(id.contentWindow.document.body.scrollHeight, id.contentWindow.document.lastChild.scrollHeight) + 'px' }); - if (!delay) { - // For whatever reason, browsers will report different heights - // after the initial height setting. Delaying a second height - // setting seems to work most of the time to fix this. - this.iframeResize.bind(this, id, true).delay(0.5); - } + val = Math.max(id.contentWindow.document.body.scrollHeight, id.contentWindow.document.lastChild.scrollHeight); + id.setStyle({ height: val + 'px' }); + + // For whatever reason, browsers will report different heights + // after the initial height setting. Try expanding IFRAME up to + // 5 times in 20px increments. If still scrolling, give up to + // prevent infinite loops (and giant IFRAMES). + do { + if (id.contentWindow.document.body.scrollHeight == id.contentWindow.document.lastChild.scrollHeight) { + break; + } + + val += 20; + id.setStyle({ height: val + 'px' }); + } while (++i <= 5); } }; -- 2.11.0