我正在尝试动态调整SharePoint网页上Web部件的宽度和高度,以使其填满整个可用空间。似乎没有办法从SharePoint Web部件属性编辑器窗口中选择宽度和高度的百分比。而且,通过代码动态设置Web部件实例会导致SharePoint抛出异常,指出不支持比例尺寸。是否有任何方法可以使用JavaScript来实现这一点?我看到类似的东西使用jQuery完成,但不完全符合我的要求(而且我对jQuery不够熟悉,无法自己想出解决方案)。
有一个Web部件可用,在这里执行此操作。您还可以在TechNet社区上查看来自“potta vijay kumar”的解决方案(我也在那里找到了该Web部件):
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
是 iframe 的 ID。
EndUserSharePoint 提供了一个 jQuery 解决方案。
var head=$('td.ms-bodyareaframe');
$("#myFrame").height(head.position.height()).attr('src',unescape(loc));
$("#myFrame").parent().height(head.height()-50);
这将完美地调整包含 iframe 的 Web 部件的大小。
注意:这可能不适用于所有情况。