SharePoint Page Viewer: automatically adjust iFrame height#

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>

Tuesday, May 31, 2005 1:25:10 PM UTC #     | 

 

All content © 2012, Mart Muller
On this page
This site
Calendar
<February 2012>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910
Archives
Sitemap
Disclaimer

Powered by: newtelligence dasBlog 1.9.7174.0

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

Send mail to the author(s) E-mail

Theme design by Jelle Druyts