Getting scrollHeight of dynamically created iframe

M

Martin

There seems to be some strange behaviour when trying to get the
scrollHeight and scrollTop of an iframe in IE6.

I have tried several ways of getting these values when the iframe is
written into the html. The following return the correct values in IE6,
where the iframe's id is 'f':

f.document.body.scrollHeight
f.document.body.scrollTop
window.frames['f'].document.body.scrollHeight
window.frames['f'].document.body.scrollTop
document.frames('f').document.body.scrollHeight
document.frames('f').document.body.scrollTop

The following give a strange value for scrollHeight (definitely not
the length of the contents of the iframe) and scrollTop is always 0:

document.getElementById('f').document.body.scrollHeight
document.getElementById('f').document.body.scrollTop
document.all.f.document.body.scrollHeight
document.all.f.document.body.scrollTop

When I dynamically create the iframe, using myFrame =
document.createElement('IFRAME'), I get the same strange values as
above when I do this:

myFrame.document.body.scrollHeight
myFrame.document.body.scrollTop

However this works as correctly in Opera 7. I find this all very
confusing. Can anybody shed light onto how I might get the correct
values in IE6 when using the createElement() method?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top