| JavaScript - Window control | | Print | |
Window control
The Window object defines methods to move, resize, and scroll windows, and methods to give keyboard focus to and take focus away from windows. For example:
// Automatically scroll 10 pixels a second
setInterval("scrollBy(0,1)", 100);
See moveTo( ), moveBy( ), resizeTo( ), resizeBy( ), scrollTo( ) scrollBy( ), focus( ) and blur( ) in the Window object entry of the reference section for more information.
More important than these methods that manipulate an existing window are the open( ) method that creates a new browser window and the close( ) method that closes a script-created window. The open( ) method takes three arguments. The first is the URL to be displayed in the new window. The second is an optional name for the window. If a window by that name already exists, it is reused and no new window is created. The third argument is an optional string that specifies the size of the new window and the features, or chrome, that it should display. For example:
// Open a new window
w = open("new.html", "newwin", // URL and name
"width=400,height=300," + // size
"location,menubar," + // chrome
"resizable,scrollbars,status,toolbar");
// And close that new window
w.close();
Note that most browsers only allow scripts to close windows that they have opened themselves. Also, because of the recent proliferation of nuisance pop-up advertisements on the Web, some browsers do not allow scripts to open new windows at all.
| Users' Comments (0) |
|
No comment posted





