Finding Values and More with Web Page Dialog Boxes
(Page 1 of 4 )
In this conclusion to a five-part series, we'll wrap up our discussion of what you can do with web page dialog boxes. Among other things, we include some tips you'll need to keep in mind when you include web page dialog boxes in your commercial projects.
Accessing Value in a Descendant Window
You may recall that in the previous part of this series, we left off with an explanation of how to access the value in an ancestor window. The process of accessing a value in a descendant window is similar. You can put the following code in the JavaScript in every window:
function followOrReturn(name)
{
if (window.name == name)
{
return window.self;
}
else
{
return window2.followOrReturn(name);
}
}
This function, like the one before it, is called by another function or event in the same window. The function receives the name of the descendant window that interests you as an argument. It first checks to see if the name it has received is the name of its window. If that is true, it determines the reference of the window it is in and returns it; otherwise, it forwards the request to the immediate child window, calling the same function there.
In order to call a function in the child window, it needs a reference to the child window. We have been opening child windows as follows:
childReference = window.open();
where “window ” is the window having the JavaScript code. As you can see, each time we do this, we have a reference to the child window in the parent window. From the parent window you can use this reference to do something in the child window.
When the followOrReturn(name) function is in every page, it allows messages to be propagated from child to child. This enables you to get the reference of a descendant window, if you know the name of that descendant window. You can then use the reference in whatever ancestor window you are in, to access value in the descendant window.
Next: Easy Way of Creating Descendant Dialog Boxes >>
More HTML Articles
More By Chrysanthus Forcha