The SharePoint "Page Viewer Webpart" that comes with the standard installation is a usefull application to display pages or sites in a Sharepoint environment. There is however a problem setting the height for this webpart when that page that is loaded in the iframe varies in height. In some cases scrollbars appear even if the height is set in webpart property. Our javascript guy has created a script that can be included in the iFrame page to set this height automatically depending on the page height.
There is one restriction with this script, the page should in the same domain as the Sharepoint environment.
Inlcude de following code (which is a first version) into the page you will load in the iFrame:
<script type="text/javascript">
function resizeToFit(that){
var objNode = (typeof(this.nodeName)=='undefined') ? that : this ;
var objIframe = window.parent.document.getElementById('resizeToFit');
var intScrollX, intScrollY, intWinWidth, intWinHeight, intMaxWidth, intMaxHeight;
var intWhileCount = 0;
do{
// scroll the document by 1 pixel
window.scrollTo(1,1);
// measure the scroll position
intScrollX = (document.all) ? document.body.scrollLeft : window.pageXOffset ;
intScrollY = (document.all) ? document.body.scrollTop : window.pageYOffset ;
// measure window size
intWinWidth = (document.all) ? document.body.offsetWidth : window.innerWidth ;
intWinHeight = (document.all) ? document.body.offsetHeight : window.innerHeight ;
// if the scroll position is not 0
if(intScrollX>0){
// make the window larger
window.resizeBy(32,0);
// make the iframe larger
if(objIframe!=null && !document.all) objIframe.style.width = (objIframe.style.width=='') ? '64px' : (parseInt(objIframe.style.width) + 32) + 'px';
}
if(intScrollY>0){
// make the window larger
window.resizeBy(0,32);
// make the iframe larger
if(objIframe!=null && !document.all) objIframe.style.height = (objIframe.style.height=='') ? '64px' : (parseInt(objIframe.style.height) + 32) + 'px';
}
// count the steps
intWhileCount += 1;
}while((intScrollX>0 || intScrollY>0) && intWhileCount<900);
}
function waitToFit()
{
setTimeout("resizeToFit()",100);
}
onload = waitToFit;
</script>