472,981 Members | 1,241 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,981 software developers and data experts.

Getting scrollHeight of dynamically created iframe

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.scrollH eight
document.getElementById('f').document.body.scrollT op
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?
Jul 23 '05 #1
1 24472


Martin wrote:
There seems to be some strange behaviour when trying to get the
scrollHeight and scrollTop of an iframe in IE6.
window.frames['f'].document.body.scrollHeight
window.frames['f'].document.body.scrollTop
window.frames.frameName (or window.frames['frameName']) is the best
cross-browser way to access the frame window object, and then
window.frames.frameName.document gives you the document in that frame
window.

When I dynamically create the iframe, using myFrame =
document.createElement('IFRAME'),


Make sure you give your iframe element a name and an id attribute
var iframe = document.createElement('iframe');
iframe.id = iframe.name = 'f';
then make sure you insert the iframe element into the document e.g.
document.body.appendChild(iframe);
after that you can then access
window.frames.f
respectively
window.frames.f
as the frame window.
There is a difference between the HTML <iframe> element object in the
document tree and the frame window object,
document.createElement('iframe') returns an HTMLIframeElement object
that represents the <iframe> element object in the document tree, the
same way as there are HTMLParagraphElement objects for <p> elements in
teh document tree, but an <iframe> element also necessitates the browser
to create a frame window to load the document referenced by the frame
and if you want to access that frame window cross browser then you
should use
<iframe name="f" id="f"
respectively
var iframe = document.createElement('iframe');
iframe.id = iframe.name = 'f';
to be able to script
window.frames.f
and
window.frames.f.document

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: BGMeshi | last post by:
Hi, The following javascript code (serving a main HTML page) dynamically creates IFRAME to contain other HTML page. Everyting works OK, however when I am trying to access the main HTML page...
1
by: Malkalypse | last post by:
Hello, I have been having some trouble with this one, so I decided to strip it down to its simplest form. I think I found the root of the problem, but I don't know how to solve it. I need a link...
3
by: Quentin | last post by:
Hey there ! I made my own WebControl, that inherits from WebControls, and i added an HtmlTable to it. I would like to include a file, dynamically, to one of its cells... I've already searched,...
5
by: Angel | last post by:
Is there a way to create an IFRAME dynamically via VB.NET. In other words creating the HTML element in the server side code? thanks in advance....
9
by: aatcbbtccctc | last post by:
Hi folks I've googled for an answer to this, with no success. Can someone please jump in, and put me out of my misery! (I'm sure it's quite simple) I have an invisible IFRAME, and a visible...
5
by: maya | last post by:
hello, how do you load an iframe dynamically? I don't mean url inside iframe, but iframe itself.. thank you..
1
by: Andrew Poulos | last post by:
If I do this: el = document.createElement("iframe"); el.src = "test.htm"; el.name = "frm"; // or el.setAttribute("name","frm"); document.body.appendChild(el); the iframe gets created but the...
12
by: mistral | last post by:
Can anybody tell me how to get source code of page in iframe? (popup window is clickable image). When I right click on this popup border to view source, i see just as follows <html> <head>...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.