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

How can I access and element in the Top Window from Inside an Iframe

0 views
Skip to first unread message

Mel

unread,
Apr 17, 2007, 8:30:44 PM4/17/07
to
I need to access an element of my top window from inside an IFrame
within that window.

I tried:
parent.MYFRAME.document.getElementById("LHS");

and i get a "Access Denied"

is there a way to do this ?

thanks in advance

Mel

unread,
Apr 17, 2007, 8:30:51 PM4/17/07
to

Yansky

unread,
Apr 17, 2007, 9:09:18 PM4/17/07
to

If the iframe src from the same domain as the parent document?

There's a new jQuery plugin that was just released yesterday that
might help you: http://groups.google.com/group/jquery-en/browse_thread/thread/e1b2c367f354aead/

wisestpotato

unread,
Apr 18, 2007, 9:27:19 AM4/18/07
to
On 18 Apr, 01:30, Mel <MelHer...@gmail.com> wrote:
> I need to access an element of my top window from inside an IFrame
> within that window.
>
> I tried:
> parent.MYFRAME.document.getElementById("LHS");
>
> and i get a "Access Denied"
>

You should be using just:

parent.document.getElementById("LHS")

That is, the MYFRAME bit shouldn't be there.

Also, the document loaded within the iframe needs to be on the same
server as the parent document. Javascript can't access documents
across different domains for security reasons.

wp.

Mel

unread,
Apr 18, 2007, 10:56:40 AM4/18/07
to
On Apr 18, 6:27 am, wisestpotato <wisestpot...@googlemail.com> wrote:

when I use
parent.document.getElementById("LHS")

i get "Access Denied" can you please help ?

wisestpotato

unread,
Apr 18, 2007, 11:25:11 AM4/18/07
to
On 18 Apr, 15:56, Mel <MelHer...@gmail.com> wrote:
> when I use
> parent.document.getElementById("LHS")
>
> i get "Access Denied" can you please help ?

Is the document within the iframe on the same server, at the same
domain, as the parent document that is hosting the iframe? If not, you
will get the permission denied error.

wp.

Randy Webb

unread,
Apr 18, 2007, 1:39:33 PM4/18/07
to
wisestpotato said the following on 4/18/2007 11:25 AM:

> On 18 Apr, 15:56, Mel <MelHer...@gmail.com> wrote:
>> when I use
>> parent.document.getElementById("LHS")
>>
>> i get "Access Denied" can you please help ?
>
> Is the document within the iframe on the same server, at the same
> domain, as the parent document that is hosting the iframe?

Same domain required: yes (with an exception)
Same *server* required: Not even close.

The exception is sub-domains with the document.domain property set.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/

wisestpotato

unread,
Apr 19, 2007, 5:42:14 AM4/19/07
to
On 18 Apr, 18:39, Randy Webb <HikksNotAtH...@aol.com> wrote:
> wisestpotato said the following on 4/18/2007 11:25 AM:
>
> > Is the document within the iframe on the same server, at the same
> > domain, as the parent document that is hosting the iframe?
>
> Same domain required: yes (with an exception)
> Same *server* required: Not even close.
>

I did not say that the same server is required, not did I mean to
imply that - sorry if I was unclear. I was trying to whittle down the
possible problems by getting a clearer idea of the situation.

wp.

0 new messages