Principles of Active Client Pages: the Script Approach - Source Code
(Page 2 of 4 )
The source code for the file of the frame is:
<html>
<script type="text/javascript">
document.write(parent.theArray[parent.pInx])
</script>
</html>
Yes, it is very short. It has to be like that, since we always have to be changing all (or almost all) of its content. Its initial content is downloaded with the frameset, as a string value of the first element of the array.
For the frame file, you have just the start and end HTML tags, and a little JavaScript. All that the script does is write into the document (page) the value of an element in the array of the frameset script. It uses the expression "document.write()," which generally replaces all the content of the page. The argument for this expression is
parent.theArray[parent.pInx]
The parent here refers to the frameset. This is followed by a dot, then the array in the frameset script. The index of the array object here is
parent.pInx
Remember that pInx is a variable in the frameset script. The value of this variable is an integer, which can be changed by script. The integer is always an index of the array. So to access it from the frame, just as to access the array from the frame, you need to begin with "parent" followed by a dot. So the value of pInx determines the page that we see.
Next: String Content >>
More JavaScript Articles
More By Chrysanthus Forcha