Why does the DOM have a window and an “I”?

Why does the DOM have an object with a name selfand another one windowif they are the same? To add to the confusion windowhas a property self, therefore:

window === window.self === self

Why is that? Which one should I use?

+5
source share
3 answers

selfdefined by the javascript environment and points to a [global] object (but is not part of the specification, and therefore may not be), but windowis part of the DOM specification. Most browsers windowuse it as a [global] object, but this is not always the case.

, self == window.self , - self (window). , , window.self == window.self.

, [global] sef, var global = this; .

+5

self, window.self, , (, location window.location).

, ? :

if(window.top != window.self) {
  alert("We're in a frame");
}
+1

self window.self. .

Regarding what exists both window, and selfin the context of a webpage is selfalways equal window(as far as I know). But I think this doesn’t always have to be that way - Javascript / ECMAScript is not limited to being used on a web page that has a DOM.

In terms of use, both must be safe to use in the normal context of an AFAIK web page. See @Nick Comment for good arguments to use window. Nonetheless.

0
source

All Articles