Window.parent is always undefined in an iframe

I recently ran into this weird problem, I was trying to reference the parent window in an iframe, but somehow window.parent or parent is always undefined.

I had a problem using window.top, but this question still haunts me.

Why is window.parent undefined?

It's a .NET web app if it helps.

Refresh . I would like to add that both parent and child iframes point to the same domain (localhost). As far as the code goes, I tried the following code:

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

      

where something never happens, I also tried

alert(parent)

      

and

alert(window.parent)

      

they always come out as null.

+2


source to share


2 answers


Heck, this finally turned out to be a coding error - someone accidentally overridden the parent in another function:

parent = blah

      



while he had to use

var parent = blah

      

+4


source


Security - where IS window.parent ....



also checks the case of the property ... js is case sensitive ...

-2


source







All Articles