Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

FAQ Topic - How do I access a frame's content? (2012-09-26)

2 views
Skip to first unread message

FAQ server

unread,
Sep 25, 2012, 7:00:03 PM9/25/12
to
-----------------------------------------------------------------------
FAQ Topic - How do I access a frame's content?
-----------------------------------------------------------------------

To reference another frame on the _same domain_:

The content window of a `FRAME` or `IFRAME` can be
accessed by 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; // Nonstandard, but widely supported.
var fdoc = iframeEl.contentDocument; // DOM2 HTML Standard.

A global 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:
<URL: http://jibbering.com/faq/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`.

<URL: http://en.wikipedia.org/wiki/Same_origin_policy>
<URL: http://www-archive.mozilla.org/docs/dom/domref/dom_frame_ref5.html>
<URL: https://developer.mozilla.org/en/DOM/window.postMessage>
<URL: 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.

0 new messages