奇怪的jquery iframe高度显示
我在iframe加载时调用了以下方法:奇怪的jquery iframe高度显示,jquery,iframe,Jquery,Iframe,我在iframe加载时调用了以下方法: function resizeIframe() { $("#content").css("height", ""); $("#content").css("width", ""); var iFrameHeight = $('iFrame').contents().height(); var iFrameWidth = $('iFrame').contents().width(); $("#content"
function resizeIframe() {
$("#content").css("height", "");
$("#content").css("width", "");
var iFrameHeight = $('iFrame').contents().height();
var iFrameWidth = $('iFrame').contents().width();
$("#content").css("height", iFrameHeight);
$("#content").css("width", iFrameWidth);
}
调用此函数时,文本下方有大量空白,因此iframe高度约为1457px。但奇怪的是,当我添加这样的警报时:
function resizeIframe() {
$("#content").css("height", "");
$("#content").css("width", "");
var iFrameHeight = $('iFrame').contents().height();
var iFrameWidth = $('iFrame').contents().width();
alert($("#content").height()); <-------------this alert
$("#content").css("height", iFrameHeight);
$("#content").css("width", iFrameWidth);
}
函数resizeIframe(){
$(“#content”).css(“height”,“height”);
$(“#内容”).css(“宽度”,“宽度”);
变量iframehight=$('iFrame').contents().height();
变量iFrameWidth=$('iFrame').contents().width();
警报($(“#content”).height();通常,您需要为父页面中的iFrame
设置大小。如果不设置,则将采用父容器的全宽和全高,并为框架窗口设置此大小。
因此,$('iFrame').contents().height()
将返回您已经知道的实际渲染高度
我不明白你用这些代码的意图
如果你想检查框架页面的原始动态大小,这可能很难。我还没有任何想法
编辑:您可以使用类似这样的脚本来修复动态大小问题。
你能在你的答案中包括两个演示吗(例如使用)。另外,从你的问题标题中删除打字错误。它应该是怪异的,而不是Wierd
。更好的是,选择一个更具描述性的标题。你什么时候调用该方法?@KevinB-下面是它的调用方式:$(文档)。就绪(函数(){$(“#iFrame”)。加载(函数(){resizeIframe();});}