Java Reference
In-Depth Information
Let's see another example. The following creates a resizable 250-by-250-pixel window, with a location
fi eld and menu bar:
var newWindow = window.open(“”,”myWindow”,
”width=250,height=250,location,menubar,resizable”);
A word of warning, however: Never include spaces inside the features string; otherwise some browsers
will consider the string invalid and ignore your settings.
Scripting Between Windows
You've taken a brief look at how you can manipulate the new window's properties and methods, and
access its document object using the return value from the window.open() method. Now you're going
to look at how the newly opened window can access the window that opened it and, just as with frames,
how it can use functions there.
The key to accessing the window object of the window that opened the new window is the window
object's opener property. This returns a reference to the window object of the window that opened the
new window. So the following code will change the background color of the opener window to red:
window.opener.document.bgColor = “red”;
You can use the reference pretty much as you used the window.parent and window.top properties
when using frames.
Try It Out Inter-Window Scripting
Let's look at an example wherein you open a new window and access a form on the opener window
from the new window.
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title>Chapter 8: Example 5</title>
<script type=”text/javascript”>
var newWindow;
function btnOpenWin_onclick()
{
var winTop = (screen.height / 2) - 125;
var winLeft = (screen.width / 2) - 125;
var windowFeatures = “width=250,height=250,”;
windowFeatures = windowFeatures + “left=” + winLeft + “,”;
windowFeatures = windowFeatures + “top=” + winTop;
newWindow = window.open(“ch08_examp5_popup.htm”, “myWindow”,
windowFeatures);
}
function btnGetText_onclick()
{
Search WWH ::




Custom Search