11

I want to insert another web page inside a SP2010 page. With "Page Viewer Webpart", it only takes a small portion of the vertical space available on my SP page.

I had the same problem in SP2007, and solved it with:

<style type="text/css">
  .Myframe
  {width:100%; height:expression(document.body.clientHeight-100);}
</style>
<iframe id="I1" name="I1" class="Myframe" width="100%" frameborder="0" >
  Your browser does not support inline frames or is currently configured not to display inline frames.
</iframe>
<script type="text/jscript" language="javascript">
  I1.location.href= 'http://mywebsite/page.aspx';
</script>

Now, in SP2010, I can't reproduce the same behavior.
Any solutions for this simple requirement?

Nelson Reis
  • 215
  • 1
  • 3
  • 9
  • http://blogs.msdn.com/b/malag/archive/2008/09/15/story-of-a-mischievous-page-viewer-web-part.aspx – Neil Richards Feb 07 '11 at 19:46
  • I've worked with this code and can't get it to work. Also, the content editor does not have the source editor in SP 2010 as far as I can tell. I have tried programatically adding the content editor and using variations of the javascript to no avail. – Matthew Steven Monkan Feb 08 '11 at 23:37
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Waqas Sarwar MVP Aug 26 '14 at 05:10

2 Answers2

4

Neither of the answers really worked for me... so I came up with my own script. Put this inside the page you are displaying using the Page Viewer Web part near the end; probably right before the </body> tag.

<script type="text/javascript">
(function(){
    var D = document;
    //http://james.padolsey.com/javascript/get-document-height-cross-browser/
    var dheight = Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );

    //http://stackoverflow.com/a/935537/98933
    var parentFrame = parent.document.getElementById(window.name);
    parentFrame.style.height = dheight + 'px';
})();
</script>

It works by getting the parent document, looking up the iframe it lives in and setting the iframe height to be a static value.

Kit Menke
  • 4,193
  • 6
  • 32
  • 40
  • I put this code just like it is in a master page inside of my $(document).ready(function () and it works! I never set the height property on the webpart and when I load pages into it, the scrollbars disappear! Wonderful! I'd give another +1 if I could. However, if you have another iframe on the underlying page, you'll see it's scrollbars. – bgmCoder Sep 10 '14 at 21:34
1

took me a long time to find out what to do, but I solved it. It has to do with the DocType and rendering. I removed the XHTML doctype from a custom masterpage and set from 8 to 7.

Now the rendering works again. Maybe the HTML doctype can be put in place of the XHTML one, maybe the rendering can be put to 8 - but it works for me - and i dont want to look at it anymore :-)