Home arrow JavaScript arrow Page 3 - 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 access Values and Contents in the Parent Window?
(Page 3 of 5 )

Yes. All you need is a reference to the parent window. The DOM window object has a property called “opener.” This is used to return a reference to the parent window. Consider the following statement:

var myParent = window.opener;

The phrase “window.opener” in the statement returns the reference to the immediate parent window. This reference is assigned to the “myParent” variable.

How do I set or read JavaScript variable in the Parent Window?

Assume that in the parent window you have the following JavaScript code:

<script type="text/javascript">

var lastName;

//the rest of the JavaScript code …

</script>

From the JavaScript of the child window, you can set this parent variable giving the value “Smith” as follows:

myParent = window.opener;

myParent.lastName = "Smith";

So, in the JavaScript in the child, you use the reference of the parent window; this is followed by a dot, and then the variable in the parent window. The value (Smith) for the variable is assigned with the equal sign.

The following code in the JavaScript of the child window will read the value of the variable of the parent window and assign it to the name variable in the child.

myParent = window.opener;

var name = myParent.lastName;

How do I set or read HTML Element Content in the Parent Window?

In the JavaScript of the child window the following statement would access the value of an element in the parent window:

myParent = window.opener;

myParent.document.getElementById('I1').value

Assume that you have the following element in the parent window:

<input type=”text” id=”I1”>

The following statement in the child script (window) would set the value of the Input Text Control to “I love you.”

myParent.document.getElementById('I1').value = "I love you.”;

And the following code in the child script would read the value of the Input Text control from the parent window into the variable, name, in the child window:

var name = myParent.document.getElementById('I1').value;


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 4 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials