contentWindow - portable alternative?

J

Jon Drukman

i'm using the following construct to access form fields within an
iframe:

var x = document.getElementById('prefs_iframe').contentWindow.document.forms["prefs_form"];

works great in IE and Mozilla/Firefox. doesn't work in Safari. my
DHTML reference book says that contentWindow is only supported in
NN7/IE5.5(Win). what's the DOM-friendly approach to accessing form
fields within an iframe?

the book says to use contentDocument.defaultView but i get [null] when
i try that.

-jsd-
 
R

Richard Cornford

Jon said:
i'm using the following construct to access form fields within an
iframe:

var x =
document.getElementById('prefs_iframe').contentWindow.document.forms["pr
efs_form"];

works great in IE and Mozilla/Firefox. doesn't work in Safari. my
DHTML reference book says that contentWindow is only supported in
NN7/IE5.5(Win). what's the DOM-friendly approach to accessing form
fields within an iframe?

The best cross-browser method is to access the IFRAME's global/window
object as a member of the - frames - collection of its containing
window/frame and go into the IFRAME document through its - document -
property. That becomes slightly more cross-browser when you give the
IRAME a name attribute in addition to an ID (They can, and probably
should, be identical):-

frames['prefs_iframe'].document.forms["prefs_form"];
the book says to use contentDocument.defaultView but i
get [null] when i try that.

That really doesn't make much sense as - defaultView - is specified as
an implementation of the - AbstractView - interface, and its -
document - property will refer back to the same object as was referred
to by - contentDocument - (making it a pointless side track).

Richard.
 
J

Jon Drukman

Richard Cornford said:
The best cross-browser method is to access the IFRAME's global/window
object as a member of the - frames - collection of its containing
window/frame and go into the IFRAME document through its - document -
property. That becomes slightly more cross-browser when you give the
IRAME a name attribute in addition to an ID (They can, and probably
should, be identical):-

frames['prefs_iframe'].document.forms["prefs_form"];

here's what i came up with through my own experimentation:

var x = document.getElementById('prefs_iframe');

if (x.contentWindow) {
x = x.contentWindow.document.forms["prefs_form"];
}
else {
x = x.contentDocument.forms["prefs_form"];
}

works on IE, Moz & Safari. your version seems much more compact
although not very DOM-centric.

-jsd-
 
T

Thomas 'PointedEars' Lahn

Jon said:
"Richard Cornford" <[email protected]> wrote in message news:<[email protected]>...

Please do not write attribution novels. The name of the person which
text is quoted is sufficient to follow the discussion. Anything else
can be retrieved via the headers of the postings. Duplicating it
renders discussions less legible.
[...]
frames['prefs_iframe'].document.forms["prefs_form"];

here's what i came up with through my own experimentation:

var x = document.getElementById('prefs_iframe');

if (x.contentWindow) {
x = x.contentWindow.document.forms["prefs_form"];
}
else {
x = x.contentDocument.forms["prefs_form"];
}

works on IE, Moz & Safari. your version seems much more compact
although not very DOM-centric.

Yes, it *seems* to be so. The `frames' collection is part of a
widespread, yet not fully standardized DOM, called "DOM Level 0"
which originates from NN/IE3+ and is still supported in current
browsers (and upon which the W3C DOM is built) while the W3C DOM
is not always fully supported. (Yes, there has been a DOM before
the W3C DOM and there are still other DOMs!, namely the Gecko
DOM). I wonder what you think "DOM-centric" would mean here.


PointedEars
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen in
Thomas 'PointedEars' Lahn
[email protected]>...

Please do not write attribution novels. The name of the person which
text is quoted is sufficient to follow the discussion. Anything else
can be retrieved via the headers of the postings. Duplicating it
renders discussions less legible.

Ignore him. Current Internet draft standards encourage attribution
details.

The pointed one only wishes to allow that which he himself finds useful.
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top