Monthly Archives: December 2008

Resize iFrame to height of content, from iFrame, without an ID

There must be a more graceful way to reference the current iframe without knowing its ID?

function resizeIFrame() {
	var iframe = $('iframe',parent.document.body);
	var doc;
	var iHeightPadding;
	for (var i=0, j=iframe.length; i<j; i++) {
		if (iframe[i].contentDocument) {
			doc = iframe[i].contentDocument;
			iHeightPadding = 35;
		} else {
			doc = iframe[i].contentWindow.document;
			iHeightPadding = 0;
		}
		if (doc === document) {
			//located our iframe!
			$(iframe[i]).height(doc.body.scrollHeight + iHeightPadding);
			break;
		}
	};
}