Posts

Showing posts from January, 2016

jQuery iFrame Sizing & auto-sizing iframes

Note: Due to browser security limitations related to cross-site scripting, this solution works only for iframe page content called from the same domain. Example  http://host.sonspring.com/iframe/ Download:  http://sonspring.com/journal/jquery-iframe-sizing First off, let me say that frames are bad and should be avoided. That being said, if you must use frames then I suppose the iframe would be the least of all the evils. Occasionally, project requirements arise such that you simply cannot get around having to use these pesky elements. One thing I have always detested about iframes is they are not aware of the dimensions of their content. Setting the width of an iframe is trivial, because you generally know how wide its contents will be. The pain point often comes when specifying height, because pages always vary in length. With a fixed height, the iframe is either too tall or short. This causes one of two undesirable outcomes: cutoff content, or a scrollbar. One of the