From: FAQ server on
-----------------------------------------------------------------------
FAQ Topic - How do I access a frame's content?
-----------------------------------------------------------------------

To reference another frame on the _same domain_:

A frame's content window can be found from the ` frames ` collection.

Example:

var fwin;
fwin = self.frames[0]; // or:
fwin = self.frames["iframeName"];

or from the ` IFRAME ` or ` FRAME ` element:

var iframeEl = document.getElementById("myFrame");
var fwin = iframeEl.contentWindow;

An identifier ` moomin ` in the the iframe's content window,
is accessed as ` fwin.moomin `.

To communicate between frames on _different_ domains:

Where supported, (IE8, Firefox 3, Opera 9, Safari 4), use
` window.postMessage( message[, port], otherDomain); `.

Example:

http://jibbering.com/example/postMessage.html

Where ` window.postMessage ` is not supported, the ` window.name ` property
can be set on the other window, which can poll for updates to that
property using ` setInterval(checkWinName, 100); ` where ` checkWinName `
is a function that polls to check the value of
` self.name `.

http://en.wikipedia.org/wiki/Same_origin_policy

http://www-archive.mozilla.org/docs/dom/domref/dom_frame_ref5.html

https://developer.mozilla.org/en/DOM/window.postMessage

http://msdn.microsoft.com/en-us/library/cc197015(VS.85).aspx


The complete comp.lang.javascript FAQ is at
http://jibbering.com/faq/

--

The sendings of these daily posts are proficiently hosted
by http://www.pair.com.

From: Garrett Smith on
Dr J R Stockton wrote:
> In comp.lang.javascript message <4bca3d79$0$286$14726298(a)news.sunsite.dk
>> , Sat, 17 Apr 2010 23:00:02, FAQ server <javascript(a)dotinternet.be>
> posted:
>
>> FAQ Topic - How do I access a frame's content?
>
>> To reference another frame on the _same domain_:
>
> Surely one can reference the frame independently of the domain (and can
> use that to set its style), and it is access to the content which
> depends on the domain? If so, move that paragraph down past that to
> which it does not apply.
>

The entry is regarding the frame/window object, not an IFRAME element.
The `frames` collection answers how to do that.

>
>> A frame's content window can be found from the ` frames ` collection.
>>
>> Example:
>>
>> var fwin;
>> fwin = self.frames[0]; // or:
>> fwin = self.frames["iframeName"];
>>
>> or from the ` IFRAME ` or ` FRAME ` element:
>>
>> var iframeEl = document.getElementById("myFrame");
>> var fwin = iframeEl.contentWindow;
>>
>> An identifier ` moomin ` in the the iframe's content window,
> xx A global ... x

Good call on both of those.

>> is accessed as ` fwin.moomin `.
>
>
> That is at best incomplete. In sitedata.htm, I use
>
> Ifr.style.display="block"
> FILE = Ifr.contentDocument.body
> FILE = FILE.textContent || FILE.innerText // IE8 needs latter
>
> and in linxchek.htm
>
> DOC = Fram.contentDocument
> St = DOC.body.textContent || DOC.body.innerText
>
> A partial FAQ answer is a misleading answer.
>

You're accessing a the window through the iframe. That is another way to
do it, and it works.

Should the FAQ mention that approach, as well, including cross-browser
issues? It might end up being too long for an FAQ entry.
--
Garrett
comp.lang.javascript FAQ: http://jibbering.com/faq/
From: Dr J R Stockton on
In comp.lang.javascript message <4bca3d79$0$286$14726298(a)news.sunsite.dk
>, Sat, 17 Apr 2010 23:00:02, FAQ server <javascript(a)dotinternet.be>
posted:

>FAQ Topic - How do I access a frame's content?

>
>To reference another frame on the _same domain_:

Surely one can reference the frame independently of the domain (and can
use that to set its style), and it is access to the content which
depends on the domain? If so, move that paragraph down past that to
which it does not apply.


>A frame's content window can be found from the ` frames ` collection.
>
>Example:
>
>var fwin;
>fwin = self.frames[0]; // or:
>fwin = self.frames["iframeName"];
>
>or from the ` IFRAME ` or ` FRAME ` element:
>
>var iframeEl = document.getElementById("myFrame");
>var fwin = iframeEl.contentWindow;
>
>An identifier ` moomin ` in the the iframe's content window,
xx A global ... x
>is accessed as ` fwin.moomin `.


That is at best incomplete. In sitedata.htm, I use

Ifr.style.display="block"
FILE = Ifr.contentDocument.body
FILE = FILE.textContent || FILE.innerText // IE8 needs latter

and in linxchek.htm

DOC = Fram.contentDocument
St = DOC.body.textContent || DOC.body.innerText

A partial FAQ answer is a misleading answer.

--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (RFCs 5536/7)
Do not Mail News to me. Before a reply, quote with ">" or "> " (RFCs 5536/7)
From: Dr J R Stockton on
In comp.lang.javascript message <5210024f-adbf-41c3-b4b1-3b1931d987b9(a)x1
2g2000yqx.googlegroups.com>, Wed, 21 Apr 2010 17:31:09, nick
<nick___(a)fastmail.fm> posted:
>
>Another thing that might be worth mentioning is that targets in hrefs
>and forms and the second parameter to window.open will cause pages to
>load in the named (i)frame if it exists. This can be very useful in
>combination with the iframe's onload event.

If targets are mentioned, the views of W3C validators should be
included, plus how a target can be assigned by script. My js-grphx.htm
and others include script document.links[5].target = "_top" for
that.

--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk BP7, Delphi 3 & 2006.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
<URL:http://www.bancoems.com/CompLangPascalDelphiMisc-MiniFAQ.htm> clpdmFAQ;
NOT <URL:http://support.codegear.com/newsgroups/>: news:borland.* Guidelines
From: Dr J R Stockton on
In comp.lang.javascript message <hqo38s$2m7$1(a)news.eternal-
september.org>, Wed, 21 Apr 2010 16:55:05, Garrett Smith
<dhtmlkitchen(a)gmail.com> posted:
>Dr J R Stockton wrote:
>> In comp.lang.javascript message <hqjjli$4ug$1(a)news.eternal-
>> september.org>, Tue, 20 Apr 2010 00:04:16, Garrett Smith
>> <dhtmlkitchen(a)gmail.com> posted:
>>> Dr J R Stockton wrote:
>>>> In comp.lang.javascript message <4bca3d79$0$286$14726298(a)news.sunsite.dk
>>>>> , Sat, 17 Apr 2010 23:00:02, FAQ server <javascript(a)dotinternet.be>
>>>> posted:
>>>>
>>>>> FAQ Topic - How do I access a frame's content?
>>>>> To reference another frame on the _same domain_:
>>>> Surely one can reference the frame independently of the domain (and
>>>> can
>>>> use that to set its style), and it is access to the content which
>>>> depends on the domain? If so, move that paragraph down past that to
>>>> which it does not apply.
>>>>
>>> The entry is regarding the frame/window object, not an IFRAME element.
>>> The `frames` collection answers how to do that.
>> For the intended class of FAQ reader, an iframe is a type of frame.
>>If
>> the material does not apply to iframes, then "(not iframe)" is needed.
>>
>
>No, an IFRAME is an element; a `frame` is a window object.

Again, you are thinking in terms of the standard, and not considering
what ordinary people will take words to mean. You are not supposed to
be writing merely for Thomas Lahn, David Mark, and Richard Cornford.

>Can we stick to the subject and not try to classify people?

With one exception, for the FAQ there is no need to classify individuals
(exception : if there were an entry in it about Thomas). But it is
necessary to write for the right classes of people. The most important
class is not that of the professional Web coders, who should know it all
already; it is that of the normal people who wish to use JavaScript on
connection with their other work, professional or amateur.

The exception is that a FAQ maintainer needs to be in the class of good
communicators.



>>>>> is accessed as ` fwin.moomin `.
>>>> That is at best incomplete. In sitedata.htm, I use
>>>> Ifr.style.display="block"
>>>> FILE = Ifr.contentDocument.body
>>>> FILE = FILE.textContent || FILE.innerText // IE8 needs latter
>>>> and in linxchek.htm
>>>> DOC = Fram.contentDocument
>>>> St = DOC.body.textContent || DOC.body.innerText
>>>> A partial FAQ answer is a misleading answer.
>>>>
>>> You're accessing a the window through the iframe. That is another way
>>> to do it, and it works.
>>>
>>> Should the FAQ mention that approach, as well, including cross-browser
>>> issues? It might end up being too long for an FAQ entry.
>> If I had realised earlier what one can do with iframes in the
>>manner
>> above, I would have done it earlier, which would have been useful.
>> OTOH, perhaps I could have done it with frames (though, as an element,
>> iframe seems easier to manipulate).
>>
>
>I see it is confusing.
>
>An IFRAME's `contentDocument` property, or `contentWindow` property,
>where supported, will point to, respectively, either the window or the
>document that is loaded in that IFRAME.

Respectively?

>That IFRAME's contentWindow can also be accessed via the `frames`
>collection. Thus:
>
> document.getElementsByTagName("iframe")[0].contentWindow === frames[0]
>
>- is true when the (non-frameset) document contains at least one IFRAME.
>
>Does any part of that help? If so, which part?

AFAICS, contents and properties of a frame and of an iframe can ONLY be
accessed via a reference to the frame/iframe. It does not matter
whether that reference is held in a variable or is an immediately used-
and-abandoned result of a partial statement (e.g. document ... [0]
above).

Some part of the FAQ should COVER obtaining a reference to an Object,
including such as doc.gEBI, this.form, dot and ["string"], parent,
child, name, etc., and then other parts of the FAQ can just say "Get a
reference R to it (_Sec 35.26_), then ...". Example - section 9.7 (of
Version 25) would say

Using the non-standard but widely implemented innerHTML property, get a
reference R to the target (_Sec 35.26_), and assign the new material to
R.innerHTML.

REMOVE : Where "anID" is the (unique on the HTML page)
(is handled in 35.25) id attribute value of the element to modify.

If the new content is only text and is not to replace existing HTML, it
is better to modify the data property of a text node.

R.firstChild.data = "Some new Text";




>> Perhaps a new section - "How do I work with iframes?", with the
>>answer
>> written with the frame answer in mind.
>> The cross-browser issues that I recall are IE8 needing "||" above,
>>and
>> onLoad apparently not working in IE8. If there are more, it could be
>> nice to know.
>
>Use attachEvent for onload events in IFRAME elements IE.

Example?

>> In respect of cross-browser, perhaps the FAQ should cite my
>> js-datex.htm.
>>
>The js-datex.htm document might be appropriately suggested in a
>discussion about a date-related faq entry.

It also provides examples of variations between browsers, and those are
easily-tested variations.

--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (RFCs 5536/7)
Do not Mail News to me. Before a reply, quote with ">" or "> " (RFCs 5536/7)