document.body
represents the viewport when IE is running in Quirks Mode. If the document inside your iframe is in Quirks, the scrollHeight
of the body
will be equal to the height of its viewport, ie. the default height of the iframe.
If you really needed to get the document-height in Quirks Mode you would have to add an extra wrapper div to measure. A much better fix is to make sure all your documents use a Standards Mode doctype. You shouldn't be authoring anything with Quirks Mode in this decade.
Also, you shouldn't use document.all
for IE sniffing (this may go wrong for other browsers that support it), you shouldn't use iframe.document
(it's non-standard and not even documented by MSDN), and you should always add 'px'
units (IE can cope with it fine and you need it in Standards Mode).
function change_height(iframe) {
var doc= 'contentDocument' in iframe? iframe.contentDocument : iframe.contentWindow.document;
iframe.style.height= doc.body.offsetHeight+'px';
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…