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;
		}
	};
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>