Window Object
Window Object
The Window object represents the window opened in the browser.
If the document contains a frame (frame or iframe tag), the browser will create a window object for the HTML document and an additional window object for each frame.
Annotation:没有应用于 window 对象的公开标准,不过所有浏览器都支持该对象。
Window 对象集合
There is no public standard applied to the window object, but all browsers support this object. | Description |
---|---|
Window object collection |
collection frames[] |
Returns all named frames in the window.
This collection is an array of Window objects, each of which contains a frame or <iframe> in the window. The property frames.length stores the number of elements in the array frames[]. Note that the frames[] array may also reference frames that themselves have a frames[] array. | Description |
---|---|
Window object properties | property |
closed | Sets or returns the default text in the window status bar. |
document | defaultStatus Read-only reference to the Document object. See. |
Document object | history History Object. |
Read-only reference to the History object. Please parameter | Returns the height of the window's document display area. |
innerwidth | Returns the width of the window's document display area. |
length | Sets or returns the number of frames in the window. |
location | Used for the Location object of the window or frame. See Location Object. |
name | Sets or returns the name of the window. |
Navigator | Read-only reference to the Navigator object. Please parameter Navigator Object. |
opener | Returns a reference to the window that created this window. |
outerheight | Returns the external height of the window. |
outerwidth | Returns the external width of the window. |
pageXOffset | Sets or returns the X position of the current page relative to the top-left corner of the window display area. |
pageYOffset | Sets or returns the Y position of the current page relative to the top-left corner of the window display area. |
parent | Returns the parent window. |
Screen | Read-only reference to the Screen object. Please parameter Screen Object. |
self | Returns a reference to the current window. Equivalent to the Window property. |
status | Sets the text of the window status bar. |
top | Returns the topmost ancestor window. |
window | The window property is equivalent to the self property, which contains a reference to the window itself. |
|
Read-only integer. Declares the x and y coordinates of the top-left corner of the window on the screen. IE, Safari, and Opera support screenLeft and screenTop, while Firefox and Safari support screenX and screenY. |
Window object methods
Method | Description |
---|---|
alert() | Display a warning box with a message and a confirmation button. |
blur() | Remove keyboard focus from the top-level window. |
clearInterval() | Cancel the timeout set by setInterval(). |
clearTimeout() | Cancel the timeout set by the setTimeout() method. |
close() | Close the browser window. |
confirm() | Display a dialog box with a message and confirmation and cancel buttons. |
createPopup() | Create a pop-up window. |
focus() | Give keyboard focus to a window. |
moveBy() | Move the window by a specified number of pixels relative to the current coordinates of the window. |
moveTo() | Move the top-left corner of the window to a specified coordinate. |
open() | Open a new browser window or find a named window. |
print() | Print the content of the current window. |
prompt() | Display a dialog box that allows users to input. |
resizeBy() | Adjust the size of the window by a specified number of pixels. |
resizeTo() | Adjust the size of the window to the specified width and height. |
scrollBy() | Scroll the content by a specified number of pixels. |
scrollTo() | Scroll the content to the specified coordinates. |
setInterval() | Invoke a function or calculate an expression at a specified interval (in milliseconds). |
setTimeout() | Invoke a function or calculate an expression after a specified number of milliseconds. |
Window object description
The Window object represents a browser window or a frame. In client-side JavaScript, the Window object is a global object, and all expressions are calculated in the current environment. That is, there is no need for special syntax to refer to the current window; the properties of that window can be used as global variables. For example, you can just write document, without writing window.document.
Similarly, the methods of the current window object can be used as functions, such as just writing alert(), without writing Window.alert().
In addition to the properties and methods listed above, the Window object implements all the global properties and methods defined by core JavaScript.
The window property of the Window object and self PropertyThey all refer to themselves. When you want to explicitly refer to the current window rather than implicitly refer to it, you can use these two properties. In addition to these two properties, the parent property, the top property, and the frame[] array all refer to other Window objects related to the current Window object.
To refer to a frame within a window, you can use the following syntax:
frame[i] //Frame of the current window self.frame[i] //Frame of the current window w.frame[i] //Frame of window w
To refer to the parent window (or parent frame) of a frame, you can use the following syntax:
parent //Parent window of the current window self.parent //Parent window of the current window w.parent //Parent window of window w
To refer to any frame contained in the top-level window, you can use the following syntax:
top //Top-level window of the current frame self.top //Top-level window of the current frame f.top //Top-level window of frame f
A new top-level browser window is created by the Window.open() method. When calling this method, the return value of the open() call should be stored in a variable, and then that variable is used to refer to the new window. The new window's opener PropertyOn the other hand, it refers back to the window that opened it.
Generally, the methods of the Window object are operations on the browser window or frame. alert() Method,confirm() Methodand prompt MethodThey are different, interacting with users through simple dialog boxes.