ScenarioA 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.
Solutionfunction autoResizeParent() {
// if no parent don't attempt to changeif (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"; } } }
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"; } } }
// 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"; } }
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"; }
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";
// set parent frame height to my height
frameList[i].height = document.body.offsetHeight;
// force scrolling off
frameList[i].scrolling = "no";
}