[英]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.