How can a content script determine if it is in a frame (iframe) or not?

141 views
Skip to first unread message

Derek 囧

unread,
Jan 20, 2011, 7:14:06 PM1/20/11
to Chromium-extensions
How can a content script determine if it is in a frame (iframe) or
not?

Any method is ok.

Derek

Giovani Ceotto

unread,
Jan 20, 2011, 7:32:24 PM1/20/11
to Derek 囧, Chromium-extensions
You can check by using this script:

if(window.parent){
//it is
}else{
/it is not
}


--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.




--
Giovani H Ceotto
Message has been deleted
Message has been deleted

Giovani Ceotto

unread,
Jan 20, 2011, 8:21:15 PM1/20/11
to Derek 囧, Chromium-extensions
Yes, I wrote the code wrong. It actually is:

if(!window.parent){ //it is }else{ //it is not }

On Thu, Jan 20, 2011 at 10:39 PM, Derek 囧 <dere...@gmail.com> wrote:
No it doesn't work...
Anyway, i already find a solution:
if(self==top){
// in a frame
}

Thanks anyway
-Derek

> You can check by using this script:
>
> if(window.parent){
> //it is
>
>
>
>
>
>
>
>
>
> }else{
> /it is not
> }
> On Thu, Jan 20, 2011 at 10:14 PM, Derek 囧 <derek1...@gmail.com> wrote:
> > How can a content script determine if it is in a frame (iframe) or
> > not?
>
> > Any method is ok.
>
> > Derek
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Chromium-extensions" group.
> > To post to this group, send email to chromium-extensi...@chromium.org.

> > To unsubscribe from this group, send email to

> > .
> > For more options, visit this group at
> >http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.
>
> --
> Giovani H Ceotto

--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.




--
Giovani H Ceotto

Derek 囧

unread,
Jan 20, 2011, 8:24:00 PM1/20/11
to Chromium-extensions

Avishay

unread,
Feb 3, 2011, 3:54:31 AM2/3/11
to Chromium-extensions
what is the reason that window.parent returns undefined in content
scripts when asked on frames, while when asked in regular web page it
works?
(chrome 8.0.552.237)

PhistucK

unread,
Feb 3, 2011, 8:52:54 AM2/3/11
to Avishay, Chromium-extensions
There are known issues with accessing the global "window" object of other frames (be it a parent frame, or an iFrame, or a frame within a frame set) from content scripts.

You can search crbug.com for it and star it. There is already an issue filed for it, so do not file a new one, nor add comments to the existing one.

PhistucK



To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.

Johan Sundström

unread,
Feb 7, 2011, 3:48:55 AM2/7/11
to Derek 囧, Chromium-extensions
On Thu, Jan 20, 2011 at 16:14, Derek 囧 <dere...@gmail.com> wrote:
How can a content script determine if it is in a frame (iframe) or
not?

If you had no luck with top !== self, try if (typeof window.frameElement !== 'undefined') instead. Chances are that will work better (whether you can actually access the frame element of the parent window or not).

Any method is ok.

Good luck!

--
 / Johan Sundström, http://ecmanaut.blogspot.com/

Shadab Ahmed Ansari

unread,
Feb 7, 2011, 3:59:21 AM2/7/11
to Johan Sundström, Derek 囧, Chromium-extensions
How about 

top === window

2011/2/7 Johan Sundström <oya...@gmail.com>

--
Reply all
Reply to author
Forward
0 new messages