Rob wrote:
Hi Richard,
Thanks for helping. I've got some questions below.
Richard Cornford wrote: Rob wrote:
<snip> Thanks for the tip about finding the frame. However,
as I said in my post, finding the frame isn't the problem.
The code I posted above does find the frame.
No it does not. The - top.document.getElementsByTagName("FRAME"); - call
returns a collection of FRAME _elements_ in the top document, if you
what easy access to the documents contained in the frames you should go
through the window/global object for each frame, so through the -
frames - collection.
Well I know I'm misunderstanding something. I though frames were frame
elements. I still don't understand what you are saying. Can you write a
code snippet that shows me how to return the value from an input with
id='GetThis' on a frame named MainFrame.
Frames are HTML elements and also DOM objects. The
document.getElementsByTagName() method returns a collection, which is a
DOM object but it isn't a DOM element object or an HTML element.
<URL:http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-75708506>
e.g. (in the example I'll use divs because it's simpler, frames work the
same way for getElementsByTagName())
<html><title>Test getElementsByTagName</title>
<div id="firstDiv">here is a div</div>
<div id="secondDiv">here is another div</div>
<script type="text/javascript">
var divs = document.getElementsByTagName('div');
alert(
'There are ' + divs.length + ' divs'
+ '\nThe first has id ' + divs[0].id
+ '\nThe scond has id ' + divs[1].id
);
</script>
</html>
In the above, document.getElementsByTagName('div') returns a collection
of the two divs. A reference to the collection is assigned to the
variable 'divs'.
To access the first div, use divs[0] and to access the second use divs[1].
A collection is a bit like an array - it has a special length property
and the members can be accessed by index. If there is only one frame in
a document, then:
var f = document.getElementsByName('frame')
will return a collection with a length of one. To access that element,
use - f[0] - just like an array (but please remember, collections aren't
arrays).
What I can't seem to find is the document in the
frame or any form in the frame.
<snip>
As your collection is a collection of FRAME elements you will not find
that they have - document - properties except where they do, and those -
document - properties may refer to the document that contains the
element (i.e. top.document) on browsers such as IE 5.
You will find browsers where the FRAME elements have a -
contentDocument - property that is a reference to the contained
document, but going through the - frames - collection is as consistent,
cross-browser and reliable a method as is available.
Where is this documented so I can look it up.
Rather than using the document.getElementsByTagName() method, some
browsers (e.g. IE) have a document.frames collection which is similar to
other collections like document.images and document.links.
Unfortunately, the frames collection isn't part of the W3C DOM 2 HTML
specification and it isn't supported by all browsers - e.g. Firefox.
The properties of the HTMLDocument interface are here:
<URL:http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-26809268>
There are a number of collections:
readonly attribute HTMLCollection images;
readonly attribute HTMLCollection applets;
readonly attribute HTMLCollection links;
readonly attribute HTMLCollection forms;
readonly attribute HTMLCollection anchors;
'frames' isn't among them.
--
Rob
Group FAQ: <URL:http://www.jibbering.com/faq/>