Share via


How to autoresize parent frame height from child frame

Scenario
A parent document contains a frame that loads a file which content is dynamic and you want the frame to not scroll and autosize the height of the frame.

Solution
function autoResizeParent() {

// if no parent don't attempt to change
if (parent != null) {

var frameList = parent.document.body.getElementsByTagName("iframe");

// is there any frames?

if (frameList != null) {

for (var i = 0; i < frameList.length; i++) {

var srcName = frameList[i].src;

srcName = srcName.substr(srcName.lastIndexOf("/"));

var srcParent = document.location.pathname.substr(document.location.pathname.lastIndexOf("/"));

alert("Parent=" + srcParent + "\nFrame="+ srcName);

// found myself

if (srcParent == srcName) {

// set parent frame height to my height

frameList[i].height = document.body.offsetHeight;

// force scrolling off

frameList[i].scrolling = "no";

}

}

}

}

}