Didn't work so hot here in FF1.5.2. Moving up through the sizes was fine but moving down through them left extra space and alternating between medium and large progressively lengthened the page. There is also the matter of the top window being resized while the page is being viewed. Things also tended to break down with smaller top window sizes (800x600 was particularly poor). But, I liked the basic idea.
Now, I only tested this with IE6, Opera8.54 and FF1.5.2 with the following DOCTYPE on each page but, it should work with other DOCTYPEs or none. Mixing DOCTYPEs among the various pages is probably a bad idea.
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
I used this script call in the head of each page that was to appear in the iframe:
HTML Code:
<script type="text/javascript" src="rzPIframe.js">
/* Resize Iframe Script © John Davenport Scheuer
As first seen in http://www.dynamicdrive.com/forums
User Name: jscheuer1
This Credit Must Remain for Legal Use
*/
</script>
With this as the contents of rzPIframe.js:
Code:
/* Resize Iframe Script © John Davenport Scheuer
As first seen in http://www.dynamicdrive.com/forums
User Name: jscheuer1
This Credit Must Remain for Legal Use
*/
function resizeParentIframe(){
function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}
parent.document.getElementsByName(window.name)[0].style.height=''
var resizeHeight=document.all? iecompattest().scrollHeight : iecompattest().offsetHeight;
parent.document.getElementsByName(window.name)[0].style.height=resizeHeight + 'px'
}
if ( document.getElementsByName && window.name && location.href!==top.location.href && parent.document.getElementsByName(window.name)[0].tagName.toLowerCase()=='iframe' ) {
if ( typeof window.addEventListener != "undefined" ) {
window.addEventListener( "load", resizeParentIframe, false );
parent.window.addEventListener( "resize", resizeParentIframe, false );
}
else if ( typeof window.attachEvent != "undefined" ) {
window.attachEvent( "onload", resizeParentIframe );
parent.window.attachEvent( "onresize", resizeParentIframe );
}
else {
if ( window.onload != null ) {
var oldOnload = window.onload;
window.onload = function ( e ) {
oldOnload( e );
resizeParentIframe();
};
}
else
window.onload = resizeParentIframe;
if ( parent.window.onresize != null ) {
var oldOnresize = parent.window.onresize;
parent.window.onresize = function ( e ) {
oldOnresize( e );
resizeParentIframe();
};
}
else
parent.window.onresize = resizeParentIframe;
}
}
Most of the code is just to get it to 'play nice' with other scripts that might happen to be on the parent or sub pages and to check that the objects and methods used are available.
Bookmarks