IFRAME problems

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

IFRAME problems

Steven Elliott-2
Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.0.6)
Gecko/20060728 Firefox/1.5.0.6

This is a problem when two IFRAMES reside in a main HTML document. When two
IFRAMES exist in a main document the second IFRAME does not seem to
correctly reference certain elments (i.e. the DOM and Javascript) of parent
document.

For instance I have a main document parent.html:
<code>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script type="text/javascript" language="javascript">
        function getParent() { alert(³parent called²); }
    </script>
</head>
<body>
    <div id=²parentDiv²></div>

    <iframe name="iframe1" src="iframe1.html"></iframe>
    <iframe name="iframe2" src="iframe2.html"></iframe>

</body>
</html>
</code>

In iframe2.html if I call parent.getParent() I get a ³parent.getParent() is
undefined² error.  But if I call ³parent.parent.getParent()² I get the
expected alert.

In iframe2.html if I call parent.document.getElementById(³parentDiv²) I get
a ³undefined² error.  On the otherhand if I call
parent.parent.document.getElementById(³parentDiv²) I get the expected
HTMLDivElement.

In iframe1.html if I call in the body, onload=²parent.getParent()² I get the
expected alert and likewise parentDiv is also referenced correctly.

On the otherhand when I call parent.location from iframe2 I get the correct
URL ......parent.html.  So it seems some elements of parent.html can be
referenced from iframe2 as parent (window.parent acts the same) while others
seem to be as if iframe2 was contained within iframe1 and parent.html can
only be referenced indirectly through iframe1 (i.e. parent.parent...)

If I just move iframe2 before iframe1 then iframe2 behaves as iframe1 did
and iframe1 has the same problems as iframe2.

This seems to be wrong according to W3C HTML(XHTML Transitional)
specification so I would appreciate if someone could explain this behavior
to me.

FWIW IE6 exhibits similar behavior so I assume it is a fault in my
understanding.

Thanks,

Steven
_______________________________________________
dev-tech-dom mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-dom
Reply | Threaded
Open this post in threaded view
|

Re: IFRAME problems

Martin Honnen-3
Steven Elliott wrote:

> Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.0.6)
> Gecko/20060728 Firefox/1.5.0.6
>
> This is a problem when two IFRAMES reside in a main HTML document. When two
> IFRAMES exist in a main document the second IFRAME does not seem to
> correctly reference certain elments (i.e. the DOM and Javascript) of parent
> document.


> FWIW IE6 exhibits similar behavior so I assume it is a fault in my
> understanding.

Can you post a URL where the described behavior occurs?


--

        Martin Honnen
        http://JavaScript.FAQTs.com/
_______________________________________________
dev-tech-dom mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-dom
Reply | Threaded
Open this post in threaded view
|

Re: IFRAME problems

Eli Friedman
In reply to this post by Steven Elliott-2
First off, I'd suggest trying naming your function something other than
getParent, which might be causing problems.  I don't really know a clear
cause for your problem, though.  It seems to work fine on my computer,
although I haven't tested over HTTP (the problem could be
cache-related).  Have you tried pressing shift-refresh?

Second, a link to an example page would be nice.

Steven Elliott wrote:

> Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.0.6)
> Gecko/20060728 Firefox/1.5.0.6
>
> This is a problem when two IFRAMES reside in a main HTML document. When two
> IFRAMES exist in a main document the second IFRAME does not seem to
> correctly reference certain elments (i.e. the DOM and Javascript) of parent
> document.
>
> For instance I have a main document parent.html:
> <code>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
>     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml">
> <head>
>     <script type="text/javascript" language="javascript">
>         function getParent() { alert(³parent called²); }
>     </script>
> </head>
> <body>
>     <div id=²parentDiv²></div>
>
>     <iframe name="iframe1" src="iframe1.html"></iframe>
>     <iframe name="iframe2" src="iframe2.html"></iframe>
>
> </body>
> </html>
> </code>
>
> In iframe2.html if I call parent.getParent() I get a ³parent.getParent() is
> undefined² error.  But if I call ³parent.parent.getParent()² I get the
> expected alert.
>
> In iframe2.html if I call parent.document.getElementById(³parentDiv²) I get
> a ³undefined² error.  On the otherhand if I call
> parent.parent.document.getElementById(³parentDiv²) I get the expected
> HTMLDivElement.
>
> In iframe1.html if I call in the body, onload=²parent.getParent()² I get the
> expected alert and likewise parentDiv is also referenced correctly.
>
> On the otherhand when I call parent.location from iframe2 I get the correct
> URL ......parent.html.  So it seems some elements of parent.html can be
> referenced from iframe2 as parent (window.parent acts the same) while others
> seem to be as if iframe2 was contained within iframe1 and parent.html can
> only be referenced indirectly through iframe1 (i.e. parent.parent...)
>
> If I just move iframe2 before iframe1 then iframe2 behaves as iframe1 did
> and iframe1 has the same problems as iframe2.
>
> This seems to be wrong according to W3C HTML(XHTML Transitional)
> specification so I would appreciate if someone could explain this behavior
> to me.
>
> FWIW IE6 exhibits similar behavior so I assume it is a fault in my
> understanding.
>
> Thanks,
>
> Steven
_______________________________________________
dev-tech-dom mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-dom
Reply | Threaded
Open this post in threaded view
|

Re: IFRAME problems

Steven Elliott-2
Thanks all for you interest.

The problem seems to be a combination of name collision and cache related as
Eli suggested.  I very much like Javascript and its interaction with DOM but
keeping track of name collisions and scope is difficult.  Scope can be
mitigated somewhat using OO but name collisions go for the most part
undetected and the problem is aggravated when references exist in a stale
cache (i.e. reload the parent page but the page referenced by an inline
frame doesn't get reloaded).

Anyway, thanks again for confirming that the problem was most likely with
implementation ,)

Steven


_______________________________________________
dev-tech-dom mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-dom