我有一个页面,其中包含加载所有内容的iframe。我一直试图设置i帧的高度,一旦我加载了帧。
此代码正在父代
上运行$iFrame.load(function() {
this.style.height =
this.contentWindow.document.body.offsetHeight + 30 + 'px';
console.log('onload height', this.style.height);
});
控制台为我提供了onload height 1229px
然而,如果我在加载iFrame的页面上运行它
window.document.body.offsetHeight
它告诉我1535
就像没有得到相同的价值。
我在脚本加载后使用$(function() {})
设置父iframe
if(inIframe()) {
$('iframe#page-content', window.parent.document).height( $(window).height() + 'px');
}
它给了我与上面提到的相同的值,根据页面的不同,似乎总是超过500或更多
有什么想法吗?
答案 0 :(得分:0)
这样做:
$iFrame.load(function() {
this.style.height = '100%';
console.log('onload height', this.style.height);
});