| Previous Topic | Tutorial Table of Contents | Next Topic |
The Window ObjectThe window is more than just the place where the document is loaded. It is also the "chrome" around the document, such as the scrollbars, the menu bar and the status area at the bottom of the browser. You can use JavaScript to open new windows on top of the existing window. This is done with the window.open() method, which takes the following arguments:window.open("url", "windowName", "windowAttributes") (Note: arguments in italics are optional) Arguments "url": you can specify any url to open in the sub window. If you specify no url (i.e., ""), then JavaScript will open a blank window in which you can write what you want (see document.write() method for that). "windowName": you can specify a name or handle for addressing the object later. However, this feature is not very useful because the open() method returns a reference to the new object. Thus, when you use this method your code should assign the reference to a new variable: var small = window.open("", "large", "width="2"00,height=350") In this example, the handle or reference name for referring to the new sub window is "small",not "large". You can leave this attribute blank. One use for this name is that you can assign it the same name that you give a target window in an <a href="someplace.html" target="window_name"> tag. When you do this, the window that the JavaScript open() command opens will be in the same window that the anchor tag target is set for. "windowAttributes": This argument allows you to specify a number of attributes of the new sub window, such as what "chrome" features are available (statusbar, scrollbars, toolbar, etc.), whether the window is resizable (Note: Macintosh windows are always resizable), what the width and height are, and, in NN4, where the new window should appear on the screen, in addition to other features. See Table 6.1 below for a listing of window attributes that can be specified. Important Note: the window attributes must be specified as a comma-delimited list with NO SPACES between the elements, or else the browser will ignore your specifications and set the attributes to the default settings. Table 6.1
All the attributes in Table 6.1 evaluate to either
a boolean value (yes/no) or a number in pixels. Thus, to specify a window with:
width: 400
height: 350
status
menubar
and is resizable
you would write:
var newWindow = window.open("", "", "width=400,height=350,status,menubar,resizable")
Alternatively, you could write:
var newWindow = window.open("", "", "width=400,height=350,status=yes,menubar=yes,resizable=yes")
These two argument lists produce identical windows.
Some attribute features are only available for NN4. One that I particularly like are screenX
and screenY, which allow the scripter to determine the position on the screen of the new window.
These attributes specify the position (in pixels) of the top left corner of the new window.
Position (0,0) is the top left corner of the browser.
Note that if you specify a position that is out of the frame of view of the screen, a run-time
error will be generated. This is not a bug, but a feature. It was installed into JavaScript
for security reasons, so that someone can't have the script doing something in a window that
is out of your sight. If you specify a screenX and/or a screenY value that is too large, the
window will appear simply put the window as far left and/or down on the screen as possible
and still be visible to the user. |
| Previous Topic | Tutorial Table of Contents | Next Topic |