[英]Create iframe with dynamic height
我想使用iframe在弹出窗口中显示远程网址的内容或网站。 但我不想修复iframe的高度。 我已经使用了一些代码
function resizeIframe(iframe) {
iframe.height = iframe.contentWindow.document.body.scrollHeight + "px";
}
对于
我尝试了另一个代码
document.getElementById('iframe1').scrollHeight();
但这不起作用。 请建议
尝试这个:
newheight = document.getElementById(iframe1).contentWindow.document.body.scrollHeight;
//For Firefox:
document.getElementById(id).height = (newheight) + "px";
//For Other:
$('#' + iframe1).css('min-height', newheight + 'px');
我觉得你错过了风格属性:
iframe.style.height = iframe.contentWindow.document.body.scrollHeight + "px";
或者对于第二个我认为你应该做的事情
$('#iframe1').height(300); //will set your Iframe height with id iframe1 to 300px
除此以外
$('#iframe1').css("height", "300px") //do the same
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.