var MAX_RETRIES_IFRAME_HEIGHT = 10; var BODY = 'body'; var MAIN_FRAME_URL = 'runInMainFrameURL'; var extra = true; function setIFrameHeight( iFrameName, maxHeight, hasContent, retries ) { var iframeWin = window.frames[iFrameName]; var theIFrame = getIFrame( iFrameName ); if ( theIFrame && iframeWin ) { var docHt = getDocHeight( iframeWin.document ); // need to add to height to be sure it will all show if ( docHt ) { if ( maxHeight && docHt > maxHeight ) { docHt = maxHeight; } // IE9 and FF needs a little extra :( if ( extra ) { docHt = docHt + 25; extra = false; } theIFrame.style.height = docHt + 'px'; } else if ( hasContent && retries <= MAX_RETRIES_IFRAME_HEIGHT ) { //document height is 0, but the hasContent says there should be content, //keep trying until there is or until we hit the maximum retries //this can happen (i think) when content has finished loading so the onLoad(...) fires //but the page has not rendered yet, so its not the correct size yet setTimeout( 'setIFrameHeight( \'' + iFrameName + '\', ' + maxHeight + ', ' + hasContent + ', ' + ++retries + ' );', 200 ); } } } function changeIFrameHeight( iFrameName, height ) { var theIFrame = getIFrame( iFrameName ); if ( theIFrame ) { theIFrame.style.height = height + 'px'; } } function getIFrame( iFrameName ) { return document.getElementById? document.getElementById(iFrameName): document.all? document.all[iFrameName]: null; } function loadiframe( iframeName, url ) { if ( window.frames[iframeName] ) { window.frames[iframeName].location = url; return false; } else { return true; } } function getFrameDocument( documentWithFrameSet, theFrame ) { if ( documentWithFrameSet.getElementById( theFrame ) ) { if ( documentWithFrameSet.getElementById( theFrame ).contentDocument ) { //W3C return documentWithFrameSet.getElementById( theFrame ).contentDocument; } else { //IE return documentWithFrameSet.frames[ theFrame ].document; } } } function runInMainFrame() { try { if ( this.name != BODY ) { findFrameDocument( parent, BODY, 1 ).location = document.getElementById( MAIN_FRAME_URL ).value; } } catch( e ) { //do nothing...must be in a window } } function findFrameDocument( window, theFrame, numChecks ) { if ( getFrameDocument( window.document, theFrame ) ) { return getFrameDocument( window.document, theFrame ); } else if ( numChecks != 5 ) { return findFrameDocument( window.parent, theFrame, numChecks + 1 ); } } // set width is still in development, not working 100% function setIFrameWidth( iframeName, maxWidth, dontResize ) { var resize; if ( dontResize ) { resize = false; } else { resize = true; } var iframeWin = window.frames[iframeName]; var theIFrame = document.getElementById? document.getElementById(iframeName): document.all? document.all[iframeName]: null; if ( theIFrame && iframeWin ) { var docWt = getDocWidth( iframeWin.document ); // need to add to width to be sure it will all show if ( docWt ) { if ( ( maxWidth ) && ( docWt > maxWidth ) ) { docWt = maxWidth; if ( resize ) { theIFrame.style.width = docWt + 'px'; } } else { theIFrame.style.width = docWt + 'px'; } } } } function getDocWidth(doc) { var docWt = 0, sw, ow; if (doc.width) { docWt = doc.width; } else if (doc.body) { if (doc.body.scrollWidth) { docWt = sw = doc.body.scrollWidth; } if (doc.body.offsetWidth) { docWt = ow = doc.body.offsetWidth; } if (sw && ow) { docWt = Math.max(sw, ow); } } return docWt; }