Max Koretskyi
Max Koretskyi

Reputation: 105517

Where is the `parent` variable that points to Window object in Chrome defined?

I just incidentally forgot to remove console.log(parent) in my experiment and it logged Window. I didn't know there's the global variable parent. Where is it defined? I'm using latest Chrome.

Upvotes: 1

Views: 264

Answers (1)

T.J. Crowder
T.J. Crowder

Reputation: 1074959

It's defined in the HTML specification, specifically here:

The parent IDL attribute, on getting, must run the following algorithm:

  1. Let windowProxy be this Window object's WindowProxy object.

  2. If there is no browsing context with windowProxy as its WindowProxy object, then return null.

  3. Let context be that browsing context.

  4. If context is a child browsing context of another browsing context parent, then return parent's WindowProxy object.

  5. Otherwise, context must be a top-level browsing context. Return context's WindowProxy object.

See also MDN.

Basically, parent is the window's parent (e.g., it's a frame or iframe), if it has one, or the window itself if it doesn't.

There's also the related, but different, opener (MDN | spec).

Upvotes: 1

Related Questions