Re: Accesing an IFrame from an internal element



"Fernando Deutsch" <fdeutschnospam@xxxxxxxxxxxxxxx> writes:

Please don't top post!

May look as nonsense code to you, because you dont know the whole context of
the application.

More likely because he knows how the DOM works.

You wrote, e.g.:
element.window
and
element.ownerDocument.window

That's just blind guessing on your part, and it works as well as
could be expected from that. The element does have an "ownerDocument"
property (as specified by W3C DOM Core), but neither the document
nor the element has a reference to a window object.

So I am looking to see what object would be the "window container" of that
img . As I have a reference to the img object I can navigate to its owner
document, and from it, I should be able to reach its window (expecting the
iframe) but I got an undefined object.

The error is your assumption that you can go from a DOM element to
the window containing the DOM document of the element. The window object
is not a DOM object, so the DOM specification doesn't say how to find
it.

You might be able to use document.defaultView, as some browsers have
that property point to the window object. It is not specified that the
defaultView should also be the global object, or a window object, and
it's not available in all browsers, so it's not a good solution.

According to the Mozilla Document Interface
http://www.mozilla.org/docs/dom/domref/dom_doc_ref.html#998664 I should be
able to get the window by the property contentWindow.

That's a property on the DOM element of the iframe in the parent document,
not on an element in the window you want to find.

You could also just do (in the parent window):
frames["iframeId"]
to get the window object of the embedded iframe with id="iframeId".

/L
--
Lasse Reichstein Nielsen - lrn@xxxxxxxxxx
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
.



Relevant Pages

  • Re: Invoking scroll method for an IFRAME object in HTML javascript
    ... scrollable IFRAME element in an HTML document? ... I know of no DOM where *this object* would have a `scroll' method. ... there are three ways to refer to the corresponding Window object. ...
    (comp.lang.javascript)
  • Re: If...else statement
    ... but could not find the window object in DOM ... DOM standard has ever specified that the ECMAScript global object (or ... as they are the same object in a browser object model) ...
    (microsoft.public.scripting.jscript)
  • Re: Dynamic select lists using optgroups again - without frameworks
    ... convertible to boolean `true' does not follow necessarily that the property ... implement the EventTarget interface of W3C DOM Level 2 Events. ... Window object instead. ... by numerous frameworks and scripts, ...
    (comp.lang.javascript)
  • Re: Dynamic select lists using optgroups again - without frameworks
    ... convertible to boolean `true' does not follow necessarily that the property ... also supporting several event listeners ... Window object instead. ... You will observe that you also don't need any DOM branching for this. ...
    (comp.lang.javascript)
  • Re: RegExp for hyphen to camelCase?
    ... You could but the global object has never been defined as an instance of the AbstractView interface. ... I would use the slightly longer, ... And the current WHAT WG drafts also try to ensure that the current praxis that browsers implement document.defaultView as the window object becomes standardized: ... in the DOM but to check for the result too. ...
    (comp.lang.javascript)