Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Expanding Iframe height to fit it's content.

Status
Not open for further replies.

shu745

Programmer
May 14, 2001
79
US
Hey all, the subject line is pretty self explanitory. I think I've seen it before but I'm not sure where.

I would greatly appreciate anyone's help with this.

Thanks much.
- Shu
 
main page
Code:
<iframe src="somePage.htm"></iframe>


somePage.htm

Code:
<body onLoad="this.parent.style='height: 100px; width: 200px;'">

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook
zen.gif

 
Not sure if this is cross-browser compatible, but...

Main page
Code:
<iframe id="iframeName" src="iframe.html"></iframe>

Iframe
Code:
<html>
<head>
<script>
function resizeMe(){
  var ifrm = parent.document.getElementById("iframeName");
  if(ifrm){
    ifrm.style.height=document.body.scrollHeight + ifrm.offsetTop;
    ifrm.style.width=document.body.scrollWidth + ifrm.offsetLeft;
  }
}
</script>
</head>
<body onLoad="resizeMe()">

Adam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top