Java Reference
In-Depth Information
The second parameter is the name you want to allocate to the new window. This is not the name you
use for scripting, but instead is used for the target attribute of things such as hyperlinks and forms.
For example, if you set this parameter to myWindow and set the target attribute of a hyperlink on the
original page to the same value (like in the following code example), clicking that hyperlink will cause
the hyperlink to act on the new window opened.
<a href=”test3.htm” target=”myWindow”>Test3.htm</a>
This means that test3.htm loads into the new window and not the current window when the user
clicks the link. The same applies to the <form /> element's target attribute. In this case, if a form is
submitted from the original window, the response from the server can be made to appear in the new
window.
When a new window is opened, it is opened (by default) with a certain set of properties, such as width
and height, and with the normal browser-window features. Browser-window features include things
such as a location entry fi eld and a menu bar with navigation buttons.
The third parameter of the open() method can be used to specify values for the height and width
properties. Also, because by default most of the browser window's features are switched off, you can
switch them back on using the third parameter of the open() method. You'll look at browser features in
more detail shortly.
Let's fi rst look at an example of the code you need to open a basic window. You'll name this window
myWindow and give it a width and height of 250 pixels. You want the new window to open with the
test2.htm page inside.
var newWindow = window.open(“test2.htm”,”myWindow”,”width=250,height=250”);
You can see that test2.htm has been passed as the fi rst parameter; that is the URL of the page you
want to open. The window is named myWindow in the second parameter. In the third parameter, you've
set the width and height properties to 250.
Also notice that you've set the variable newWindow to the return value returned by the open() method,
which is a reference to the window object of the newly opened window. You can now use newWindow to
manipulate the new window and gain access to the document contained inside it using the newWindow
.document property. You can do everything with this reference that you did when dealing with frames
and their window objects. For example, if you wanted to change the background color of the document
contained inside the new window, you would type this:
newWindow.document.bgColor = “red”;
How would you close the window you just opened? Easy, just use the window object's close() method
like this:
newWindow.close();
Search WWH ::




Custom Search