Window
The Window interface represents a the browser's window. A global variable, window, representing the window in which the script is running, is exposed to JavaScript code.
When a variable or function not previously defined is used, this means that the property or method of the window is being used.
window.alert("Oh, no!");
// same as
alert("Oh, no!");
properties
Most properties are read only.
property | description |
---|---|
document | Returns a reference to the document that the window contains. |
fullscreen | Indicates whether the window is displayed in full screen mode or not.
|
history | Reference to the History object, which provides an interface for manipulating the browser session history (pages visited in the tab or frame that the current page is loaded in). |
location | Reference to the Location object with information about the current location of the document.
|
navigator | Reference to the Navigator object, that contains information about the visitor's browser. |
frames | Array of frames. Each item represents the window object corresponding to the given frame's or iframe's content. In other words window.frames[0] is the same thing as document.getElementsByTagName("iframe")[0].contentWindow. |
parent | Reference to the parent of the current window or subframe. If a window does not have a parent, its parent property is a reference to itself. |
top | The topmost window in the hierarchy of window objects. This property is especially useful when you are dealing with a window that is in a subframe of a parent or parents, and you want to get to the top-level frameset. |
status | The text in the statusbar at the bottom of the browser. |
name | Name of the window. |
innerWidth | The width of the content area of the browser window including, if rendered, the vertical scrollbar. |
innerHeight | The height of the content area of the browser window including, if rendered, the horizontal scrollbar. |
methods
methods | description |
---|---|
open(url, windowName, [windowFeatures]) | Loads the specified resource into the browsing context (window, frame or tab) with the specified name.
If the name doesn't exist, then a new window is opened and the specified resource is loaded into its browsing context.
|
close() | Closes the current window, or the window on which it was called. |
alert(msg) | Displays an alert dialog with the optional specified content and an OK button.
|
print() | Opens the Print Dialog to print the current document. |
promt(message,default) | Displays a dialog with an optional message prompting the user to input some text.
|
confirm(message) | Displays a modal dialog with an optional message and two buttons: OK and Cancel.
true if user selected Ok button.
|
moveBy(deltaX, deltaY) | Moves the current window by a specified amount.
|
moveTo(x,y) | Moves the current window to the specified coordinates.
|
resizeBy(dx, dy) | Resizes the current window by a specified amount.
|
resizeTo(w,h) | Resizes the window.
|
scroll(x,y) | Scrolls the window to a particular place in the document.
|
scroll(options) | Scrolls the window to a particular place in the document.
|
scrollBy(dx, dy) | Scrolls the document in the window by the given amount.
|
scrollBy(options) | Scrolls the document in the window by the given amount.
|