[英]Create iframe with dynamic height
I want to show a remote url's content or site in popup using iframe. 我想使用iframe在弹出窗口中显示远程网址的内容或网站。 But i do not want to fix height of iframe.
但我不想修复iframe的高度。 I have already used some code
我已经使用了一些代码
function resizeIframe(iframe) {
iframe.height = iframe.contentWindow.document.body.scrollHeight + "px";
}
for 对于
and i have tried another code 我尝试了另一个代码
document.getElementById('iframe1').scrollHeight();
But this is not working. 但这不起作用。 Please suggest
请建议
Try this: 尝试这个:
newheight = document.getElementById(iframe1).contentWindow.document.body.scrollHeight;
//For Firefox:
document.getElementById(id).height = (newheight) + "px";
//For Other:
$('#' + iframe1).css('min-height', newheight + 'px');
I think you missed style attribute: 我觉得你错过了风格属性:
iframe.style.height = iframe.contentWindow.document.body.scrollHeight + "px";
Or for the second I think you should do something like 或者对于第二个我认为你应该做的事情
$('#iframe1').height(300); //will set your Iframe height with id iframe1 to 300px
Otherwise 除此以外
$('#iframe1').css("height", "300px") //do the same
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.