调整iFrame大小以适应内容(仅限同一域)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了调整iFrame大小以适应内容(仅限同一域)相关的知识,希望对你有一定的参考价值。
Still problematic...1. The source of the iframe content must reside on the same domain
2. if the content inside the iframe changes height, this won't adapt
3. I left Google Analytics code off the demo above, as when I added it in it seems to interfere and not resize the iframe, despite seemingly generating no errors.
Normally you set and width and height for iframes. If the content inside is bigger, scrollbars have to suffice. The script below attempts to fix that by dynamically resizing the iframe to fit the content it loads. <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js?ver=1.3.2'></script> <script type='text/javascript'> $(function(){ var iFrames = $('iframe'); function iResize() { for (var i = 0, j = iFrames.length; i < j; i++) { iFrames[i].style.height = iFrames[i].contentWindow.document.body.offsetHeight + 'px';} } if ($.browser.safari || $.browser.opera) { iFrames.load(function(){ setTimeout(iResize, 0); }); for (var i = 0, j = iFrames.length; i < j; i++) { var iSource = iFrames[i].src; iFrames[i].src = ''; iFrames[i].src = iSource; } } else { iFrames.load(function() { this.style.height = this.contentWindow.document.body.offsetHeight + 'px'; }); } }); </script> Will resize an iframe like this:
以上是关于调整iFrame大小以适应内容(仅限同一域)的主要内容,如果未能解决你的问题,请参考以下文章
完成所有 jquery ajax 请求后如何调整 iframe 的大小