473,549 Members | 3,048 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.scrollHeig ht
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.getEle mentById('f').d ocument.body.sc rollHeight
document.getEle mentById('f').d ocument.body.sc rollTop
document.all.f. document.body.s crollHeight
document.all.f. document.body.s crollTop

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

myFrame.documen t.body.scrollHe ight
myFrame.documen t.body.scrollTo p

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 24593


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.f rameName (or window.frames['frameName']) is the best
cross-browser way to access the frame window object, and then
window.frames.f rameName.docume nt gives you the document in that frame
window.

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


Make sure you give your iframe element a name and an id attribute
var iframe = document.create Element('iframe ');
iframe.id = iframe.name = 'f';
then make sure you insert the iframe element into the document e.g.
document.body.a ppendChild(ifra me);
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.create Element('iframe ') returns an HTMLIframeEleme nt object
that represents the <iframe> element object in the document tree, the
same way as there are HTMLParagraphEl ement 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.create Element('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
2639
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 elements from the child page by window.parent.document... a javascript error is accepted. Any Idea? TIA Boris
1
1816
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 in one iframe to open a page in a different iframe. I can do this normally: http://www.jonesmfgmusic.com/test/test1/ But, when the iframes are...
3
5725
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, and found HttpContext.Current.Server.Execute("mapage.aspx") but it executes the page where i call it, and not in the cell... i also tried something...
5
9738
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
11152
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 DIV: <IFRAME id=myframe style="display:none" src="..." onload="ShowNews(this)"></IFRAME>
5
6846
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
3210
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 'name' attribute is not added under IE 6. I tried setting the 'name' after appending the iframe but still no joy.
12
11123
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> <title>New offer!</title> </head> <body style="margin-left: 0%; margin-right: 0%; margin-top: 0%;
0
7446
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7956
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7809
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6041
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5088
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3498
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3480
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1058
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
763
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.