Microsoft KB Archive/278469

= How To Resize an IFrame to the Size of Its Contents Without Displaying Scroll Bars =

Article ID: 278469

Article Last Modified on 11/23/2006

-

APPLIES TO


 * Microsoft Internet Explorer 4.0 128-Bit Edition
 * Microsoft Internet Explorer 4.01 Service Pack 2
 * Microsoft Internet Explorer 4.01 Service Pack 1
 * Microsoft Internet Explorer 4.01 Service Pack 2
 * Microsoft Internet Explorer 5.0
 * Microsoft Internet Explorer 5.01
 * Microsoft Internet Explorer (Programming) 5.01 SP1
 * Microsoft Internet Explorer 5.5

-



This article was previously published under Q278469



SUMMARY
In certain situations, you may want to resize an IFrame so that all of its document contents are visible, but no scroll bars are displayed on the page. This article describes how to do this.



MORE INFORMATION
To determine the size of the IFrame's contents, you must access the height and width properties of the underlying IFrame document. Because you only have scripting access to pages that are hosted in the same domain, you can only access the properties to the pages that are hosted within the same domain (for example, Cross Frame Scripting). Therefore, the source document of the IFrame must be from the same domain as the page that contains the IFrame.

The following code demonstrates how to resize an IFrame in this way. Create a new .htm document, and paste the following HTML code. In the SRC attribute for the IFrame, you must supply an HTML page from the same domain that the IFrame loads.

NOTE: This technique may not work correctly if there are absolutely positioned elements that are residing within the IFrame.   

      This example uses try and catch to check for domain consistency, which are only available with Internet Explorer 5 and later. This error checking is included for illustration purposes and is not absolutely necessary; it only allows the script to fail gracefully.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please visit the following Microsoft Web site:

https://partner.microsoft.com/global/30000104

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:

http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS

