↑
Main Page
resizeTo
As mentioned previously, the feature string is comma-delimited and, therefore, must contain no space
before or after a comma or equal sign. For example, the following string is invalid:
window.open(“http://www.wrox.com/”, “wroxwindow”,
“height=150, width= 300, top=10, left= 10, resizable =yes”);
This string won’t work because of the spaces after the commas and other spaces around a couple of
equal signs. Just remove the spaces and it works fine:
window.open(“http://www.wrox.com/”, “wroxwindow”,
“height=150,width=300,top=10,left=10,resizable=yes”);
The
window.open()
method returns a
window
object as its function value that is also the
window
object
for the newly created window (or for the frame, if the name given is the name of an existing frame).
Using this object, it’s possible to manipulate the new window:
var oNewWin = window.open(“http://www.wrox.com/”, “wroxwindow”,
“height=150,width=300,top=10,left=10,resizable=yes”);
oNewWin.moveTo(100, 100);
oNewWin.resizeTo(200, 200);
Also using this object, it is possible to close the new window using the
close()
method:
oNewWin.close();
If there is code in the new window, it can close itself by using:
window.close();
This only works in the new window. If you try to call
window.close()
in the main browser window,
you get a message saying that a script is trying to close the window and asking if you actually want it to
close. The general rule to remember is this: Scripts can close any windows that they open, but no others.
A new window also has a reference to the window that opened it stored in the
opener
property. The
opener
property exists only on the topmost
window
object of the new window, making it safer to use
top.opener
to access it. Example:
var oNewWin = window.open(“http://www.wrox.com/”, “wroxwindow”,
“height=150,width=300,top=10,left=10,resizable=yes”);
alert(oNewWin.opener == window); //outputs “true”
In this example, a new window is opened and then its
opener
property is tested against the
window
object to prove that
opener
does indeed point to
window
(this alert displays
“true”
).
142
Chapter 5
08_579088 ch05.qxd 3/28/05 11:37 AM Page 142
Free JavaScript Editor
Ajax Editor
©
→