Author: Dynamic Drive Note: Updated April 6th, 05' for FireFox 1.x iframe height issue Description: This is version II of the original Iframe SSI script, which like the original script lets you seamlessly display external content on your page via an IFRAME. It does this by dynamically resizing the IFRAME to be the height of the page contained within it, eliminating any possible IFRAME scrollbars from appearing while snugly showing the entire external content. Think of it as SSI (server side includes) emulated using DHTML! This script works in both IE5+ and NS6+, and for other browsers, supports the option to either completely hide the iframe in question or display it using its default height. Now, this script differs from the original in that you can load additional documents* into the IFRAME even after the page has loaded, and the IFRAME will dynamically adjust its height to fit the new document. So use this script if you need to not only display external content via the IFRAME tag, but intend to change this content after the page has loaded. *All external pages loaded into the iframe must be from the same domain as the page the iframe tag is inserted in. Setting the iframe's src to an external site such as "http://www.google.com" will not work, since the script cannot probe and detect the height of pages from external domains. Configuring the script To configure this script, first, set the variables inside the script of Step 1 per the comments. As you can see, you can specify more than one iframe on the page in which the script should dynamically resize. Secondly, for the code of Step 2, be sure the ID (ie: "myframe") matches the ID entered into the script, so the script knows which IFRAMEs to adjust. You may also change the width attribute (ie: 100%) to a different value, as the script only changes the height of the iframe, but not the width. Thirdly, in the script of Step 1, there is a variable that toggles whether browsers that don't support this script (non IE5+/NS6+) should still see the iframe(s) or not. Generally you should choose to hide the iframe in these non compatible browsers (Opera 7 included), as the iframe's height is hardwired in these cases, and part of the external page most likely will be clipped and unviewable to the viewer if the external page's height exceeds the iframe's default height. Last but not least, as shown in the demo above, you can actually use links on your main page to load a page into your IFRAME (with the IFRAME automatically resized to that page's height of course). To do so, the link should look like this: Link where "myframe" is the ID of the IFRAME you wish to load a page into, and "external.htm", the path to the page on your site to load. |