iframe problem (contentWindow or contentDocument)

3,119 views
Skip to first unread message

berlinsurfer

unread,
Apr 12, 2010, 12:37:51 PM4/12/10
to MooTools Users
Hi folks,
I'd very much like to send a form within an iframe (using
contentDocument or contentWindow).
Therefore I have to distinguish between the beloved Internet Explorer
and other (working) browsers. I've came across Browser.Engine.trident
(being true for IE) and Browser.Engine.gecko (being true for FF).
Does anyone know if only the IE makes the contentWindow approach ?
Otherwise I could write:

var doc = (Browser.Engine.trident)?
iframe.contentWindow:iframe.contentDocument;

Or is there a smoother Moo Way ?
Thanks in advance,
Jan

Roman Land

unread,
Apr 12, 2010, 12:46:31 PM4/12/10
to mootool...@googlegroups.com
Read this:
---

References to the window generated by the iframe and to the document loaded into the iframe can be obtained via the frames array using the name attribute.

window.frames[iframeName]
window.frames[iframeName].document

The frames array method of referencing has broad support, even among quite old browsers, as long as you attach a name attribute to the iframe. For best results, use both name and id.

For more up-to-date browsers, the document inside the iframe can also be referenced via contentWindow (IE win) and contentDocument (DOM) properties of the iframe element:

// IE5.5+ windows
document.getElementById(iframeId).contentWindow
document.getElementById(iframeId).contentWindow.document

or,

// DOM 
document.getElementById(iframeId).contentDocument

An example demonstrates back and forth communication between the document containing the iframe and the document contained within it.

---

I have taken this shamelessly from here: http://www.dyn-web.com/tutorials/iframes/

HTH
Roman



--
To unsubscribe, reply using "remove me" as the subject.



--
---
"Make everything as simple as possible, but not simpler."

- Albert Einstein

Fábio M. Costa

unread,
Apr 12, 2010, 12:56:22 PM4/12/10
to mootool...@googlegroups.com
Nice, Roman! Thanks for helping.


--
Fábio Miranda Costa
Solucione Sistemas
Engenheiro de interfaces

berlinsurfer

unread,
Apr 12, 2010, 5:08:17 PM4/12/10
to MooTools Users
Thank you very much !

> > An example <http://www.dyn-web.com/tutorials/iframes/refs.php>demonstrates back and forth communication between the document containing


> > the iframe and the document contained within it.
> > ---
>
> > I have taken this shamelessly from here:
> >http://www.dyn-web.com/tutorials/iframes/
>
> > HTH
> > Roman
>

Reply all
Reply to author
Forward
0 new messages