An instance of Window represents a single browser frame (viewport); it may be either a top-level frame (e.g., a tab) or an HTML frame or iframe element. It provides both the global namespace (so its properties usually need not be prefixed by it) and the global scope (so its properties may be accessed from anywhere within it). Note that its otherwise global scope does not apply to other frames.
To prevent XSS attacks, properties of windows from one domain cannot be accessed by scripts from another.
When the current scope contains a homonym of a Window property, the Window property is hidden. To avoid this, always reference Window properties (except window
or self
), for example alert
, as either window.alert
or self.alert
.
W3C | Mozilla | Microsoft |
---|---|---|
[1] | [2] | [3] |
Properties[]
closed[]
Data type | boolean |
---|---|
Standard | none |
Documentation | Mozilla, Microsoft |
Indicates whether the user has closed this window; useful in the context of popups, which exist independent from other windows.
document[]
Data type | HTMLDocument |
---|---|
Standard | none |
Documentation | Mozilla, Microsoft |
The page which this window is displaying.
frames[]
Data type | HTMLCollection |
---|---|
Standard | none |
Documentation | Mozilla, Microsoft |
A list of all frame
and iframe
elements which this window contains.
history[]
Data type | History |
---|---|
Standard | none |
Documentation | Mozilla, Microsoft |
Exposes methods which allow navigation through the history of the current session (i.e., tab or frame).
location[]
Data type | Location |
---|---|
Standard | none |
Documentation | Mozilla, Microsoft |
Stores and changes the current URL and its components.
name[]
Data type | string |
---|---|
Standard | none |
Documentation | Mozilla, Microsoft |
The window's name, as passed to Window.open
.
opener[]
Data type | Window |
---|---|
Standard | none |
Documentation | Mozilla, Microsoft |
In Mozilla, a reference to the window whose open method initialized this window, if any (null
otherwise). In Internet Explorer, a null
value which may be set by scripts. (Microsoft says it is only available to frame and iframe pages, but does not specify what it is in others.)
parent[]
Data type | Window |
---|---|
Standard | none |
Documentation | Mozilla, Microsoft |
If the current window is contained in another, this is the container. Otherwise, this is equal to window.
self[]
Data type | Window |
---|---|
Standard | Window Object 1.0 |
Documentation | Mozilla, Microsoft |
The less common synonym of window.
status[]
Data type | string |
---|---|
Standard | none |
Documentation | Mozilla, Microsoft |
The text in the status bar. Both Mozilla-based browsers and Internet Explorer provide the option to disable it; Mozilla disables it by default.
top[]
Data type | Window |
---|---|
Standard | none |
Documentation | Mozilla, Microsoft |
The top-level or "root" window (may also be the current window).
window[]
Data type | Window |
---|---|
Standard | Window Object 1.0 |
Documentation | Mozilla, Microsoft |
Points to its owner, i.e. window.window === window
. See the top of this page.
Methods[]
alert[]
Data type | function |
---|---|
Return type | undefined |
Parameter list | message (string) |
Standard | none |
Documentation | Mozilla, Microsoft |
Displays message in a dialog window with an OK button.
Go here to see a real alert box.
message[]
Something you want to tell the user.
blur[]
Data type | function |
---|---|
Return type | undefined |
Parameter list | none |
Standard | none |
Documentation | Mozilla, Microsoft |
Removes focus from this window.
clearInterval[]
Data type | function |
---|---|
Return type | undefined |
Parameter list | interval (number) |
Standard | none |
Documentation | Mozilla, Microsoft |
Cancels the identified interval.
interval[]
A number corresponding to the scheduled interval which is to be canceled.
close[]
Data type | function |
---|---|
Return type | undefined |
Parameter list | none |
Standard | none |
Documentation | Mozilla, Microsoft |
Closes this script-generated window. If the window was not generated by a script, one of the following occurs:
- If the browser is Mozilla, an error occurs.
- If the browser is Internet Explorer, the user is presented with a confirm dialog according to which the page will be closed or preserved.
confirm[]
Data type | function |
---|---|
Return type | boolean |
Parameter list | message (string) |
Standard | none |
Documentation | Mozilla, Microsoft |
Displays message in a dialog window with Cancel and OK buttons; returns a value which represents whether the user clicked OK.
Go here to see the confirm box.
message[]
A yes-or-no question, usually of the form, "Do you really want to [...]?" In many cases, an undo mechanism is more appropriate.
open[]
Data type | function |
---|---|
Return type | boolean |
Parameter list | url (string), [name (string)], [features (string)], [replace (boolean)] |
Standard | none |
Documentation | Mozilla, Microsoft |
Requests url in the window (or tab) identified by name; if necessary, makes such a window first.
url[]
A URL which defaults to the empty string. The empty string opens a blank page.
name[]
Optional. The window's name; corresponds to the HTML target
attribute; defaults to "_blank"
. For the relevant naming rules, see HTML 4.01 §6.16 Frame target names. For how the browser is to behave in relation to the name, see §B.8 Notes on frames and §16.3.2 Target semantics.
features[]
Optional.
replace[]
Optional. If true
, causes Microsoft Internet Explorer to overwrite the current page's history item with the given url. Only applies when name refers to the current window.
prompt[]
Data type | function |
---|---|
Return type | string |
Parameter list | message (string), default (string) |
Standard | none |
Documentation | Mozilla, Microsoft |
Displays message in a dialog window with Cancel and OK buttons, and a text input; returns the value in the text input when the user clicks OK, or null
if the user clicks Cancel.
message[]
A question which typically requires a detailed answer.
default[]
Optional; if passed, used as the text input's initial value.
scroll[]
Data type | function |
---|---|
Return type | undefined |
Parameter list | x (number), y (number) |
Standard | none |
Documentation | Mozilla, Microsoft |
Scrolls to a particular set of coordinates in the document.
scrollBy[]
Data type | function |
---|---|
Return type | undefined |
Parameter list | x (number), y (number) |
Standard | none |
Documentation | Mozilla, Microsoft |
Scrolls the document in the window by the given amount.
scrollTo[]
Data type | function |
---|---|
Return type | undefined |
Parameter list | x (number), y (number) |
Standard | none |
Documentation | Mozilla, Microsoft |
Scrolls to a particular set of coordinates in the document.
setInterval[]
Data type | function |
---|---|
Return type | number |
Parameter list | code (function or string), msDelay (number) |
Standard | none |
Documentation | Mozilla, Microsoft |
Executes the given code every msDelay milliseconds; returns a unique integer which, when passed to clearInterval, will cancel the interval.
code[]
Either a function to be called or a string to be evaluated. As with eval, best practices recommend a function over a string.
msDelay[]
A number of milliseconds by which each execution of the given code is to be delayed.