Home arrow JavaScript arrow Page 4 - Roots of Crys`s ACP Document Phase Approach
JAVASCRIPT

Roots of Crys`s ACP Document Phase Approach


In this second part of a twelve-part series on Active Client Pages (ACP), I give you the roots that give rise to my approach. One way to learn is by asking questions. We shall use that learning method here. Some of the questions are: can you reference a previously opened page? How can you get and set contents in a page that has just been loaded? When DOM was invented, Active Client Pages technology was not envisioned, so we have to ask these questions.

Author Info:
By: Chrysanthus Forcha
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
July 10, 2009
TABLE OF CONTENTS:
  1. · Roots of Crys`s ACP Document Phase Approach
  2. · How does one open a new document from the current document?
  3. · How do I send HTML contents to a newly opened document?
  4. · Can you access the HTML content of the newly loaded document?

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Roots of Crys`s ACP Document Phase Approach - Can you access the HTML content of the newly loaded document?
(Page 4 of 4 )

After loading the document, that is after using the document open() and close() methods, can the script that did the loading access the content of an HTML element in the loaded document? Yes; this can be done. Simply use the reference returned by the “document.open()” expression; follow this reference with a dot, then the expression “getElementById(ID)”, and then a dot, and then “value” or “innerHTML” (depending on what you want).

In the following example, a new page (document) is loaded; then the script that does the loading reads the value of an Input Text element in the loaded page displaying it, and then overwrites it. You can try the code.


<html>

<head>

<script type="text/JavaScript">


var pageNo = "One";


function openWrite()

{

var pageTwo = document.open();

pageTwo.write("<input id="PI2" type="text" value="two">");

pageTwo.close();


alert(pageTwo.getElementById('PI2').value);

pageTwo.getElementById('PI2').value = "second";

}

</script>

</head>

<body>

<button type="button" id="B1" onclick="openWrite()">Open New Document from Current Document</button>

</body>

</html>


Remember that if the argument of the write() method has entities, you should escape them.

The following code is similar to the code above, but instead of using an Input text element it uses a DIV element, and instead of using the value property, it uses the innerHTML property.


<html>

<head>

<script type="text/JavaScript">


var pageNo = "One";


function openWrite()

{

var pageTwo = document.open();

pageTwo.write("<div id="D2">two</div>");

pageTwo.close();


alert(pageTwo.getElementById('D2').innerHTML);

pageTwo.getElementById('D2').innerHTML = "second";

}

</script>

</head>

<body>

<button type="button" id="B1" onclick="openWrite()">Open New Document from Current Document</button>

</body>

</html>


Can you access JavaScript variables and functions in a newly loaded document?

There is no official way to do this. For the sake of simplicity, let us not worry about it.

We have answered some questions in this part of the series. Let us take a break. We continue in the next part.


DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

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