这是我想要动态显示内容的iframe。
<iframe onload='resize()' id='ifr' src='data:text/html;charset=utf-8;base64,Encoded text here' width=100% height=400px></iframe>
我试过这样的东西。。但是高度总是返回0
function resize() {
$('#ifr').height($('#ifr').contents().height());
}
这是小提琴。。
https://jsfiddle.net/zetapark/rajz6sy5/1/
$('iframe'(为您提供文档中的所有iframe,因此您应该为您的框架提供id并像$('#MYiframe'](一样使用它,或者从jquert返回的内容中获取第一个元素。
function resize() {
$('iframe')[0].height($('iframe')[0].contents().height());
}
我也在SO上发现了这一点,用于调整内容的iframe大小。
iFrame.width = iFrame.contentWindow.document.body.scrollWidth;
iFrame.height = iFrame.contentWindow.document.body.scrollHeight;