Mark Brown's Blog

TFS, Visual Studio, SQL Server, BizTalk, SharePoint, .Net, and more ...

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

}

}

}

}

}

Published Friday, June 12, 2009 5:01 PM by mab

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

Leave a Comment

(required) 
(optional)
(required) 

  
Enter Code Here: Required
Submit

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker