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