Java Reference
In-Depth Information
Let's now look at the code for the page that will be loaded in the newWindow: ch08_examp5_popup.htm.
This page contains one function, btnGetText_onclick(), which is connected to the onclick event
handler of the Get Text button in the page. It retrieves the text from the opener window's text box.
function btnGetText_onclick()
{
document.form1.text1.value = window.opener.document.form1.text1.value;
}
In this function, you use the window.opener property to get a reference to the window object of the
window that opened this one, and then use that reference to get the value out of the text box in the form
in that window. This value is placed inside the text box in the current page.
Moving and Resizing Windows
In addition to opening and closing windows, it's also possible to move and resize windows.
After opening a window, you can change its onscreen position and its size using the window object's
resizeTo() and moveTo() methods, both of which take two arguments in pixels.
Consider the following code that opens a new window:
var newWindow = window.open( myURL,”myWindow”,”width=125,height=150,resizable”);
You want to make it 350 pixels wide by 200 pixels high and move it to a position 100 pixels from the left
of the screen and 400 pixels from the top. What code would you need?
newWindow.resizeTo(350,200);
newWindow.moveTo(100,400);
You can see that you can resize your window to 350 pixels wide by 200 pixels high using resizeTo() .
Then you move it so it's 100 pixels from the left of the screen and 400 pixels from the top of the screen
using moveTo() .
The window object also has resizeBy() and moveBy() methods. Both of these methods accept two
parameters, in pixels. For example:
newWindow.resizeBy(100,200);
This code will increase the size of newWindow by 100 pixels horizontally and 200 pixels vertically.
Similarly, the following code moves the newWindow by 20 pixels horizontally and 50 pixels vertically:
newWindow.moveBy(20,50);
When using these methods, you must bear in mind that users can manually resize these windows if
they so wish. In addition, the size of the client's screen in pixels will vary between users.
Search WWH ::




Custom Search