Principles of Active Client Pages: the Script Approach - String Content
(Page 3 of 4 )
Look at the string content of the first page in the frameset document from the first part of this series. There is a button there. The onclick attribute of this button actually has the following value:
parent.pInx = 1;location.replace('myChild.htm')
There are two statements here. When the button is clicked, we have to see the next page, so the value of the pInx in the frameset script is set to 1; this is what the first statement does. The next statement asks the document of the frame to redisplay itself. In the course of redisplaying itself, it encounters the following script:
<script type="text/javascript">
document.write(parent.theArray[parent.pInx])
</script>
Now, the value of pInx is 1, so the second page is displayed. However, before this, the second element (index 1) of the array in the frameset script should have had the content of the second page, excluding the <html> and </html> tags.
Look at the string content of the first page in the frameset document from the first part of the series again. There is an external JavaScript tag at the bottom. This tag is actually
<script src="forNextPage.js"></script>
When the first page is displayed, this tag downloads the JavaScript file named forNextPage.js. Now with ACP you design your web page so that it should be rendered by the browser as it arrives at the browser.
So, while this file is being downloaded, the user is reading what has been displayed on the page, above this tag. As soon as the first page is displayed, the user starts reading it. Since the page is being rendered as it arrives, by the time the user has read anything useful, this file would have been downloaded. This is the content of the file:
parent.theArray[1] = "<html>";
parent.theArray[1] += "<head>";
parent.theArray[1] += "</head>";
parent.theArray[1] += "<body>";
parent.theArray[1] += "This is the second page seen.";
parent.theArray[1] += "</body>";
parent.theArray[1] += "</html>";
When the file is downloaded, its statements are executed, while the page in which its tag is, is still open. As you can see, the file assigns the content of the second page as a string to the second element of the array in the frameset script. These statements are executed in the frame document, so to address the array on the frameset script we have to start with the word "parent."
This external script may also have an external script tag that has content for some following page. The following code illustrates this:
parent.theArray[1] = "<html>";
parent.theArray[1] += "<head>";
parent.theArray[1] += "</head>";
parent.theArray[1] += "<body>";
parent.theArray[1] += "This is the second page seen.";
parent.theArray[1] += "<script src="forNextPage2.js"></script>";
parent.theArray[1] += "</body>";
parent.theArray[1] += "</html>";
Next: Principles of the Script Approach >>
More JavaScript Articles
More By Chrysanthus Forcha