window.parent is always undefined in an iframe

Posted by Bill Yang on Stack Overflow See other posts from Stack Overflow or by Bill Yang
Published on 2009-09-11T18:47:10Z Indexed on 2011/01/06 17:53 UTC
Read the original article Hit count: 210

Filed under:
|
|

Hi there, I have recently ran into this strange issue, I was trying to reference parent window in an iframe, but somehow window.parent or parent are always undefined.

I got around the problem by using window.top, but this question still haunts me.

Why is window.parent undefined?

This is a .NET web app, if it helps.

Update: I would like to add that both parent and child iframes are pointed to the same domain (localhost). As for code, I have tried the following code:

if (parent != null)
{
  // do something
}

where do something never happens, I also tried

alert(parent)

and

alert(window.parent)

they always come out as null.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about html