请帮助我,
iframe的第一次高度随着加载的高度而变化,但是当iframe的内容变为比现在更高的高度,并且再次降低其不会获得新的价值时。
例如,加载iframe height = 1386px新内容会更改iframe height = 3440px,并再次更改为new height = 3440px(但实际高度小于1300px)
这是我试过的
$('iframe').load(function() { document.getElementById('loaderIFRAME').style.display = 'none'; document.getElementById('myiframe').style.display = 'block'; // Set inline style to equal the body height of the iframed content. if($.browser.msie){ this.style.height = this.contentWindow.document.body.scrollHeight + 'px'; }else{ this.style.height = this.contentWindow.document.body.scrollHeight + 'px'; } }另一个也一样
function autoIframe(frameId) { try{ frame = document.getElementById(frameId); innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document; objToResize = (frame.style) ? frame.style : frame; objToResize.height = innerDoc.body.scrollHeight + 10+ 'px'; alert( objToResize.height); } catch(err){ window.status = err.message; } }我如何解决它?
Please help me out,
The very first time the iframe height is changing as per the loaded height but when the iframe contents are changed to bigger height than the present one and again coming to lower its not taking new value.
For example Loaded iframe height =1386px new content change iframe height = 3440px and again change to new height = 3440px(but actual height is very lesser than 1300px)
this is what i tried
$('iframe').load(function() { document.getElementById('loaderIFRAME').style.display = 'none'; document.getElementById('myiframe').style.display = 'block'; // Set inline style to equal the body height of the iframed content. if($.browser.msie){ this.style.height = this.contentWindow.document.body.scrollHeight + 'px'; }else{ this.style.height = this.contentWindow.document.body.scrollHeight + 'px'; } }and the other one also same
function autoIframe(frameId) { try{ frame = document.getElementById(frameId); innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document; objToResize = (frame.style) ? frame.style : frame; objToResize.height = innerDoc.body.scrollHeight + 10+ 'px'; alert( objToResize.height); } catch(err){ window.status = err.message; } }How can i solve it?
最满意答案
问题是,如果将iframe高度设置为较大的值,那么即使真实文档高度较小,它的scrollHeight也总是等于较大的值。 您可以尝试将iframe高度设置为1px,然后阅读scrollHeight属性。
$('iframe').load(function(){ try { var body = $(this).contents().find('body'); this.height = 1; this.height = body.attr('scrollHeight'); } catch(e){} });有时最好使用offsetHeight + offsetTop属性。 在这里你可以找到我的旧脚本实现。
The problem is, when you have the iframe height set to a big value, then its scrollHeight always equals the big value, even if the real document height is smaller. You can try by setting the iframe height to 1px then read the scrollHeight property.
$('iframe').load(function(){ try { var body = $(this).contents().find('body'); this.height = 1; this.height = body.attr('scrollHeight'); } catch(e){} });sometimes it is better to use offsetHeight+offsetTop properties. Here you can find my old implementation of this script.
自动Iframe高度(Automatic Iframe height)请帮助我,
iframe的第一次高度随着加载的高度而变化,但是当iframe的内容变为比现在更高的高度,并且再次降低其不会获得新的价值时。
例如,加载iframe height = 1386px新内容会更改iframe height = 3440px,并再次更改为new height = 3440px(但实际高度小于1300px)
这是我试过的
$('iframe').load(function() { document.getElementById('loaderIFRAME').style.display = 'none'; document.getElementById('myiframe').style.display = 'block'; // Set inline style to equal the body height of the iframed content. if($.browser.msie){ this.style.height = this.contentWindow.document.body.scrollHeight + 'px'; }else{ this.style.height = this.contentWindow.document.body.scrollHeight + 'px'; } }另一个也一样
function autoIframe(frameId) { try{ frame = document.getElementById(frameId); innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document; objToResize = (frame.style) ? frame.style : frame; objToResize.height = innerDoc.body.scrollHeight + 10+ 'px'; alert( objToResize.height); } catch(err){ window.status = err.message; } }我如何解决它?
Please help me out,
The very first time the iframe height is changing as per the loaded height but when the iframe contents are changed to bigger height than the present one and again coming to lower its not taking new value.
For example Loaded iframe height =1386px new content change iframe height = 3440px and again change to new height = 3440px(but actual height is very lesser than 1300px)
this is what i tried
$('iframe').load(function() { document.getElementById('loaderIFRAME').style.display = 'none'; document.getElementById('myiframe').style.display = 'block'; // Set inline style to equal the body height of the iframed content. if($.browser.msie){ this.style.height = this.contentWindow.document.body.scrollHeight + 'px'; }else{ this.style.height = this.contentWindow.document.body.scrollHeight + 'px'; } }and the other one also same
function autoIframe(frameId) { try{ frame = document.getElementById(frameId); innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document; objToResize = (frame.style) ? frame.style : frame; objToResize.height = innerDoc.body.scrollHeight + 10+ 'px'; alert( objToResize.height); } catch(err){ window.status = err.message; } }How can i solve it?
最满意答案
问题是,如果将iframe高度设置为较大的值,那么即使真实文档高度较小,它的scrollHeight也总是等于较大的值。 您可以尝试将iframe高度设置为1px,然后阅读scrollHeight属性。
$('iframe').load(function(){ try { var body = $(this).contents().find('body'); this.height = 1; this.height = body.attr('scrollHeight'); } catch(e){} });有时最好使用offsetHeight + offsetTop属性。 在这里你可以找到我的旧脚本实现。
The problem is, when you have the iframe height set to a big value, then its scrollHeight always equals the big value, even if the real document height is smaller. You can try by setting the iframe height to 1px then read the scrollHeight property.
$('iframe').load(function(){ try { var body = $(this).contents().find('body'); this.height = 1; this.height = body.attr('scrollHeight'); } catch(e){} });sometimes it is better to use offsetHeight+offsetTop properties. Here you can find my old implementation of this script.
发布评论