self
is set in the JavaScript environment and points to objeto global
, but is not part of the DOM
specification, and may not be present in the browser. While window
is part of the DOM
specification. In most browsers, window
is used as objeto global
but this may vary.
self == window.self
is not a strange thing, since they are actually the same object (how self
is used, is found to be a property of the global object ( window
)), so this is the even if you use window.self == window.self
.
To have a concise reference of the global object, you must define it on its own as follows (when in the global context):
var global = this;
Because of this, top
( window.top
) is used to reference the top window
object, for example, if you have multiple nested frames, window.top
will refer to the main page, not frames, top
is used to dect whether or not you are inside a frame:
if(window.top != window.self) {
alert("Estamos em um frame");
}
The reason why we have
window.window
(property
window
of object
window
) is to make it easy to reference
objeto global
, calling only
window
within frame, we are referencing frame,
window.window
we are referencing the global object, regardless of where