JavaScript iframe动态调整大小
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JavaScript iframe动态调整大小相关的知识,希望对你有一定的参考价值。
<script type="text/javascript">
$.noConflict();
function adjustIframes()
{
$('iframe').each(function(){
var
$this = $(this),
proportion = $this.data( 'proportion' ),
w = $this.attr('width'),
actual_w = $this.width();
if ( ! proportion )
{
proportion = $this.attr('height') / w;
$this.data( 'proportion', proportion );
}
if ( actual_w != w )
{
var h = Math.round( actual_w * proportion );
if (!isNaN(h)) {
if (console && console.log) console.log("Resizing iframe to height: " + h);
$this.css( 'height', h + 'px' );
if ($this.get(0).contentWindow.postMessage) {
$this.get(0).contentWindow.postMessage('resize', 'your website here');
}
}
}
});
}
$(window).on('resize load',adjustIframes);
});
</script>
以上是关于JavaScript iframe动态调整大小的主要内容,如果未能解决你的问题,请参考以下文章
将 iframe 内容高度设置为动态自动调整大小
动态调整 iframe 大小
Fancybox iframe 动态调整大小
Javascript 没有调整 iframe 的大小
JavaScript Iframe自动调整大小
JavaScript 根据内容调整iframe大小