Questions and Answers on Chrys`s Approach to Active Client Pages
In this eleventh part of a twelve-part series on active client pages (ACP), I give you more factors that gave rise to the Window Phase of Chrys’s Approach. We continue with the questions and answers more or less from where we left off last time.
Questions and Answers on Chrys`s Approach to Active Client Pages - Can you open a window, which will open another window, which will open another window and so on? (Page 2 of 5 )
Yes. For each of these windows, include a button that will have a statement like the following, executed:
myWindow=window.open();
The content of all of these windows can be in the master page as strings. We shall look at an example of this later.
Can I pass values as I open a new window?
Yes, of course. You do not only pass values, but you pass the content of a whole page. This content includes JavaScripts and their initialized variable, and HTML elements and their values or contents.
Can you set or read value or content in another window?
Yes. For simplicity, let us assume that each window has one document. There are more possibilities here than in the document phase. Let us look at the different cases.
How do I set or read a Child JavaScript Variable?
Assume that in the child window you have the following JavaScript code:
<script type="text/javascript">
var firstName;
//the rest of the JavaScript code …
</script>
In the JavaScript code of the parent window, you can set this variable, giving the value “John” as follows:
myWindow.firstName = "John";
So, in the JavaScript code in the parent, you use the reference to the child window; this is followed by the variable in the child window. The value is assigned with the equal sign.
You read the value of the variable from the parent window in a similar way. The following code in the JavaScript of the parent window will read the value of the variable in the child window and assign it to the name variable in the parent window.
var name = myWindow.firstName;
Again, we need the reference to the child window, and the variable in the child window to achieve this.
How do you set and read Child HTML Element Values?
In the JavaScript of the parent window the following statement would access the value of an element in the child window.
myWindow.document.getElementById(ID).value;
where myWindow is a reference to opened window.
Assume that you have the following element in the child window:
<input type=”text” id=”I1”>
The following statement in the parent script would set the value of the Input Text control to “Peter.”
The following code in the parent script would read the value of the Input Text element from the child window into the name variable in the parent window:
var name = myWindow.document.getElementById('I1').value;
How do I set and read Child HTML Content?
The method is similar to the above, but instead of using the value property, you use the innerHTML property.
Assume that you have the following element in the child window:
<div id="D1">
</div>
The following statement in the parent script would set the content of the DIV element to “New Cell Content.”
myWindow.document.getElementById('D1').innerHTML = "New Cell Content"
And the following code in the parent script would read the content of the DIV element from the child window into a variable (content) in the parent window:
var content = myWindow.document.getElementById ('D1').innerHTML;
In the above two statements, myWindow is a reference to the opened window.