Resize iframe Using jQuery on SharePoint

JavaScript to resize an iframe on a SharePoint custom page.

<script type=”text/javascript”>
// id = jQuery id of the iframe to auto resize.
// lessHeight = the amount in pixels to subtract from the browser window height when resizing the iframe.
// minHeight = the minimum height of the iframe.
function ResizeIFrame(id, lessHeight, minHeight)
{
var newHeight = window.document.body.offsetHeight – lessHeight;
var iframeHeight = (newHeight < minHeight) ? minHeight : newHeight;
$(id).height(iframeHeight);
}

// Register an iframe to be auto resized.
function ResizeIFrameRegistration(id, lessHeight, minHeight)
{
// Resize the iframe with the browser window is resized.
$(window).resize(function() { ResizeIFrame(id, lessHeight, minHeight); });
// Resize the iframe when browser page is finished loading and ready.
$(document).ready(function() { ResizeIFrame(id, lessHeight, minHeight); });
}

ResizeIFrameRegistration(“#<%= pdf.ClientID %>”, 250, 300);
</script>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s