HTML Dom tutorial 9-html Dom window object
1: Window object
Window objects are top-level objects in the Javascript level.
A window object represents a browser window or framework.
The window object is automatically created every time <body> or <frameset> appears.
2: Set of window objects
Collection |
Description |
IE |
F |
O |
Frames [] |
Return to all named frameworks in the window. This set is an array of window objects. Each window object contains a frame or <IFRAME> in the window. The frames. Length attribute stores the number of elements contained in the array frames. Note that frames referenced in the frames [] array may also contain frames, and they also have the frames [] array. |
4 |
1 |
9 |
3: properties of the window object
Attribute |
Description |
IE |
F |
O |
Closed |
Whether the window is closed. |
4 |
1 |
9 |
Defaultstatus |
Set or return the default text in the window status bar. |
4 |
No |
9 |
Document |
Read-only reference to the document object. See document objects. |
4 |
1 |
9 |
History |
Read-only reference to the history object. Please specify the history object. |
4 |
1 |
9 |
Innerheight |
Return the height of the document display area in the window. |
No |
No |
No |
Innerwidth |
Return the width of the document display area in the window. |
No |
No |
No |
Length |
Set or return the number of frames in the window. |
4 |
1 |
9 |
Location |
The location object used for the window or frame. See location object. |
4 |
1 |
9 |
Name |
Set or return the window name. |
4 |
1 |
9 |
Navigator |
Read-only reference to the navigator object. Please specify the navigator object. |
4 |
1 |
9 |
Opener |
Returns a reference to the window in which the window is created. |
4 |
1 |
9 |
Outerheight |
Returns the external height of the window. |
No |
No |
No |
Outerwidth |
Returns the external width of the window. |
No |
No |
No |
Pagexoffset |
Set or return the X position in the upper-left corner of the current page relative to the window display area. |
No |
No |
No |
Pageyoffset |
Set or return the Y position in the upper-left corner of the current page relative to the window display area. |
No |
No |
No |
Parent |
Return to the parent window. |
4 |
1 |
9 |
Screen |
Read-only reference to the screen object. Please specify the screen object parameter. |
4 |
1 |
9 |
Self |
Returns a reference to the current window. It is equivalent to the window property. |
4 |
1 |
9 |
Status |
Set the text of the window status bar. |
4 |
No |
9 |
Top |
Return to the top-level parent window. |
4 |
1 |
9 |
Window |
The window attribute is equivalent to the self attribute, which contains references to the window itself. |
4 |
1 |
9 |
- Screenleft
- Screentop
- Screenx
- Screeny
|
A read-only integer. Declares the X and Y coordinates of the upper left corner of the window on the screen. IE, Safari, and Opera Support screenleft and screentop, while Firefox and Safari support screenx and screeny. |
4 |
1 |
9 |
4: Window object Method
Method |
Description |
IE |
F |
O |
Alert () |
A warning box with a message and a confirmation button is displayed. |
4 |
1 |
9 |
Blur () |
Remove the keyboard focus from the top-Layer window. |
4 |
1 |
9 |
Clearinterval () |
Cancels the timeout set by setinterval. |
4 |
1 |
9 |
Cleartimeout () |
Cancels the timeout set by the setTimeout () method. |
4 |
1 |
9 |
Close () |
Close the browser window. |
4 |
1 |
9 |
Confirm () |
A dialog box with a message, a confirmation button, and a Cancel button is displayed. |
4 |
1 |
9 |
Createpopup () |
Create a pop-up window. |
4 |
No |
No |
Focus () |
Give the keyboard focus to a window. |
4 |
1 |
9 |
MoveBy () |
You can move the specified pixel relative to the current coordinate of the window. |
4 |
1 |
9 |
MoveTo () |
Move the upper left corner of the window to a specified coordinate. |
4 |
1 |
9 |
Open () |
Open a new browser window or find a named window. |
4 |
1 |
9 |
Print () |
Print the content of the current window. |
5 |
1 |
9 |
Prompt () |
The prompt dialog box is displayed. |
4 |
1 |
9 |
ResizeBy () |
Adjust the window size according to the specified pixel. |
4 |
1 |
9 |
ResizeTo () |
Adjust the window size to the specified width and height. |
4 |
1.5 |
9 |
Scrollby () |
Scroll the content based on the specified pixel value. |
4 |
1 |
9 |
Scrollto () |
Scroll the content to the specified coordinate. |
4 |
1 |
9 |
Setinterval () |
Calls a function or computing expression according to the specified period (in milliseconds. |
4 |
1 |
9 |
SetTimeout () |
Call a function or computation expression after a specified number of milliseconds. |
4 |
1 |
9 |
5. Description of the window object
The window object indicates a browser window or framework. In client JavaScript, window objects are global objects, and all expressions are calculated in the current environment. That is to say, to reference the current window, there is no need for special syntax. You can use the properties of that window as a global variable. For example, you can write only the document, instead of the invalid Doc ument.
Similarly, you can use the method of the current window object as a function, such as writing only alert (), instead of window. Alert ().
In addition to the attributes and methods listed above, the WINDOS object also implements all the global attributes and methods defined by the core JavaScript.
The window attribute and self attribute of the window object reference itself. These two attributes can be used when you want to explicitly reference the current window, not just implicitly reference it. In addition to these two attributes, the parent attribute, top attribute, and frame [] array all reference other window objects related to the current window object.
To reference a framework in the window, you can use the following syntax:
Frame [I] // frame of the current window
Self. Frame [I] // framework of the current window
W. Frame [I] // frame of window W
To reference the parent window (or parent framework) of a framework, you can use the following syntax:
Parent // parent window of the current window
Self. Parent // The parent window of the current window
W. Parent // The parent window of window W
To reference it from any framework contained in the top-level window, you can use the following syntax:
Top // top-level window of the current framework
Self. Top // top-level window of the current framework
F. Top // top-level window of framework F
The new top-layer browser window is created by window. open. When this method is called, the return values of open () should be stored in a variable, and then the variable should be used to reference the new window. The opener attribute of the new window references the window that opens it.
In general, the window object method is to perform some operation on the browser window or framework. The Alert () method, confirm () method, and prompt method are different. They interact with users through a simple dialog box.