Dynamic SharePoint web part width and height

Jason picture Jason · Aug 18, 2009 · Viewed 25.2k times · Source

I am trying to dynamically adjust the width and height of a web part in a SharePoint web part page so that it fills up the entire available space. It appears that there is no way to choose a percentage for width and height from the web part property editor window in SharePoint. Also, trying to dynamically set it on the web part instance through code results in SharePoint throwing an exception to the effect that proportional dimensions are not supported.

Is there any way to do this using, for example, Javascript? I've seen similar things done using jQuery, but not exactly what I'm looking for (and I'm not familiar enough with jQuery to come up with something on my own).

Answer

Alex Angas picture Alex Angas · Aug 18, 2009

There is a web part available that does this here. You can also see a solution on TechNet communities from "potta vijay kumar" (where I found that web part too):

function calcHeight() 
{ 
  //find the height of the internal page 
    var the_height= 
    document.getElementById('contentpage').contentWindow. 
      document.body.scrollHeight; 

  //change the height of the iframe 
  document.getElementById('contentpage').height= 
      the_height; 
}

contentpage is the ID of the iframe.

A jQuery solution is available from EndUserSharePoint.