Home arrow JavaScript arrow Page 2 - Questions and Answers on Chrys`s Approach to Active Client Pages
JAVASCRIPT

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.

Author Info:
By: Chrysanthus Forcha
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
September 11, 2009
TABLE OF CONTENTS:
  1. · Questions and Answers on Chrys`s Approach to Active Client Pages
  2. · Can you open a window, which will open another window, which will open another window and so on?
  3. · Can you access Values and Contents in the Parent Window?
  4. · Can I make my remarks now?
  5. · How do you really give a window a name?

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
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.”

myWindow.document.getElementById('I1').value = "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.


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 2 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials