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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IFrame Height - Dynamic Resize

Status
Not open for further replies.

ronnyjljr

IS-IT--Management
Nov 23, 2003
249
US
This isn't a question, but rather a solution to a problem that has bothered me for quite some time.

I want to dynamically resize my iFrames when they loaded a new page. Apparently, this is a task alot of developers want to accomplish. Search google for it.

I did just that and received many scripts which did not work at all. I found one that looked like it would work but the elements it modified in the page were incorrect. I worked on it for a bit and tested it in IE6 and Firefox 1.5.

So here it is, the iframe dynamic height script.
All you have to do to use it, is to pass it the id of the iframe.

I hope this alleviates some headaches!


Code:
[blue]
[green]//Place this in a .js file or enclose with script tags and put it in between <head></head> tags[/green]


<!-- Dynamically Resize iFrame height by iframe id.  -->
function iFrameHeight(iframeName)
{
	if(document.getElementById && !(document.all))
	{
		h = document.getElementById(iframeName).contentDocument.body.scrollHeight;
		document.getElementById(iframeName).height = h;
	}
	else if(document.all)
	{
		h = document.frames(iframeName).document.body.scrollHeight;
		document.all[iframeName].height = h;
	}
}

[/blue]

Your iframe should look like this...

Code:
[blue]

<iframe onLoad="iFrameHeight('events');" id="events" src="events.php" scrolling="no" marginwidth="0" marginheight="0" frameborder="0" vspace="0" hspace="0" width="100%"></iframe>



[/blue]

Enjoy,
Ron



typedef map<GiantX,gold, less<std::shortestpathtogold> > AwesomeMap;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top