473,406 Members | 2,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

contentWindow - portable alternative?

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

var x = document.getElementById('prefs_iframe').contentWin dow.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-
Jul 23 '05 #1
4 6450
Jon Drukman wrote:
i'm using the following construct to access form fields within an
iframe:

var x =
document.getElementById('prefs_iframe').contentWin dow.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.
Jul 23 '05 #2
"Richard Cornford" <Ri*****@litotes.demon.co.uk> wrote in message news:<cb*******************@news.demon.co.uk>...
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-
Jul 23 '05 #3
Jon Drukman wrote:
"Richard Cornford" <Ri*****@litotes.demon.co.uk> wrote in message news:<cb*******************@news.demon.co.uk>...


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
Jul 23 '05 #4
JRS: In article <40**************@PointedEars.de>, seen in
news:comp.lang.javascript, Thomas 'PointedEars' Lahn
<Po*********@nurfuerspam.de> posted at Thu, 8 Jul 2004 15:52:21 :
Jon Drukman wrote:
"Richard Cornford" <Ri*****@litotes.demon.co.uk> wrote in message news:<cbt01g

$9*************@news.demon.co.uk>...

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.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME ©
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demon.co.uk/news-use.htm> : about usage of News.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Jul 23 '05 #5

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

Similar topics

1
by: Richard P | last post by:
I've feel that I have tried everything possible but I still cannot get my code to work in both netscape version 6 and IE. My Javascript is in XSL files but this should not matter. I am using...
1
by: Owen Jacobson | last post by:
Salve. Does anyone have any suggestions for writing a portable 'byte' numeric type? I'm aware that (signed) char is a numeric type and can be used as such, and I assume this is the fundamental...
5
by: Henri Schomäcker | last post by:
Hi folks, I have a quite big class, which I want to use on UNIX-like systems and on win32. Until now, everything is absolutely portable. But now I need to read a directory and use the os...
5
by: Dominic | last post by:
Hi everybody, My goal is to set the height of the iframe to fit its content. There was an earlier posting which gave some useful insights. ...
385
by: Xah Lee | last post by:
Jargons of Info Tech industry (A Love of Jargons) Xah Lee, 2002 Feb People in the computing field like to spur the use of spurious jargons. The less educated they are, the more they like...
2
by: Francois Grieu | last post by:
Many C platforms lack the C99 log1p(), which computes log(1+x) accurately even when x is near 0. I'm looking for a portable (C) alternative. Somewhere I found code which can be re-expressed...
1
by: gslim | last post by:
I am trying to implement the busybox sample from // From Mark Wagner // http://blogs.crsw.com/mark/articles/642.aspx When I get to this line I get an access denied error. Could someone give me...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.