window object
Represents the browser window, frame window or dialog window of a HTML document.
The window object provides various information about the window (name, navigator, location, history, etc.), provides access to the document contained by the window and supports several useful methods (alert, confirm, addEventListener, attachEvent, etc.).
The window object can also represent a window that belongs to a frame or iframe element or a modal or modeless dialog (open, showModalDialog and showModelessDialog methods).
- If a window belongs to a frame or iframe element, then it is the child window of the window that contains the frame element. To get the parent window, use the parent property of the child window.
- If a window is opened with the open, showModalDialog or showModelessDialog method, then the window that opened it can be retrieved with the opener property.
The members of the current window are accessible directly, without using the window object as a prefix (e.g. you can use document instead of window.document), furthermore the global variables and objects are also accessible through the window object (var x = 2; alert (window.x);).
The window object is accessible from anywhere in the JavaScript code, so do not use variables with the same names as the members of the window object (although if you declare a variable with the same name as any member of the window object, the member of the window object stays accessible through the window object).
The window object is accessible from anywhere in the JavaScript code, so do not use variables with the same names as the members of the window object (although if you declare a variable with the same name as any member of the window object, the member of the window object stays accessible through the window object).
Syntax:
Properties that reference the object:
| window |
+ | object.contentWindow |
| external.menuArguments |
| document.parentWindow |
| event.source |
| event.view |
Methods that return the object:
| frames.item (nameOrIndex) |
The base interface, through which you can add new functionalities to the window object, is the Window interface.
Possible members:
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Example HTML code 1:
This example shows how to open a child window and communicate between the opener and the child windows:
|
|||||
<head> <script type="text/javascript"> function OpenChildWindow () { window.open ("childWindow.htm", "OpenerTest", "width=300, height=200"); } </script> </head> <body> First open a child window with this button: <button id="childOpener" onclick="OpenChildWindow ();">Open child window!</button> <br /><br /> You can change the text color of the button with the selection list of the child window. </body> |
|||||
|
|||||
Did you find this example helpful?
|
External links:
User Contributed Comments