PDA

View Full Version : iFrames and resizing



SolStis
Jan 19th, 2010, 01:46 PM
Hi,

Ive written some code to try and resize a page dependant on the content oof an iframe.

Code is as follows:


window.onload=sizeAdj();

function sizeAdj() {
var elFrame = document.getElementById('theFrame');
var elTable = document.getElementById('tableGrab');
var elDivMain = document.getElementById('main');
var elDivWrapper = document.getElementById('wrapper');

var the_height = elFrame.contentWindow.document.body;

elFrame.height = the_height;
elTable.height = the_height + 90;
elDivMain.height = the_height + 90;
elDivWrapper.height = the_height + 465;
}

I originally thought that I would just be able to resize the iframe and the other elements would follow suit but as you can see Ive tried to resize the other encasing elements also.

The code resizes partially in chrome but only to a certain point and not to the full height of the doc content.

Help greatly appreciated - full source content attached.

8152

Thanks

Sol

gusblake
Jan 19th, 2010, 02:32 PM
elFrame.contentWindow.document.body is just an element - if you want to know how the height of the page, use its clientHeight property:


var the_height = elFrame.contentWindow.document.body.clientHeight;


Its value will vary depending on the doctype, and it won't be the same in all browsers, so you may need to do some extra coding to get it to work properly.

Edit - also try using offsetHeight.

SolStis
Jan 19th, 2010, 02:57 PM
Thanks mate,

Ive messed around with it so much I must have forgot to include that bit,

Ill give it a go any way,

Cheers