我有一个iframe,它需要在每次加载时调整它的高度,我尝试了很多例子,但它们在IE和Chrome上都工作得很好,但不能在FireFox上工作,直到我尝试了这个,它在所有东西上都能工作
function autoResize() {
var subscriptionFrame = jQuery("#frame_name_here");
var innerDoc = (subscriptionFrame.get(0).contentDocument) ? subscriptionFrame
.get(0).contentDocument
: subscriptionFrame.get(0).contentWindow.document;
if (innerDoc.body.scrollHeight == 0)
innerDoc.location.reload(true);
subscriptionFrame.height(innerDoc.body.scrollHeight + 10);
}
<iframe src="uploadFile.xhtml" class="upload-iframe"
id="frame_name_here" onload="autoResize();"></iframe>但是有一个问题,这个脚本会多次调用onload (递归),你知道为什么吗?
发布于 2014-08-28 18:29:53
我找到了一个答案,iframe部分显示为none,这并不意味着它不在dom树中,这就是递归部分发生的原因,因为在这种情况下,iframe直到iframe被显示并且高度的内容被resize function.So读取来解决这个问题,而不是display:none,我使iframe部分在Dom树中不呈现,所以这个操作的resize方法将只读取内容一次。
https://stackoverflow.com/questions/25545336
复制相似问题