Java Reference
In-Depth Information
function returnPagesVisited()
{
var returnValue = “So far you have visited the following pages\n”;
var pageVisitedIndex;
var numberOfPagesVisited = pagesVisited.length;
for (pageVisitedIndex = 0; pageVisitedIndex < numberOfPagesVisited;
pageVisitedIndex++)
{
returnValue = returnValue + pagesVisited[pageVisitedIndex]
+ “\n”;
}
return returnValue;
}
The second function, addPage() , adds the name of a page to the pagesVisited array.
function addPage(fileName)
{
var fileNameStart = fileName.lastIndexOf(“/”) + 1;
fileName = fileName.substr(fileNameStart);
pagesVisited[pagesVisited.length] = fileName;
return true;
}
The fileName parameter passed to this function is the full fi le name and path of the visited page, so
you need to strip out the path to get just the fi le name. The format of the string will be something like
file:///D:/myDirectory/ch08_examp2_b.htm, and you need just the bit after the last / character.
So in the fi rst line of code, you fi nd the position of that character and add one to it because you want to
start at the next character.
Then, using the String 's substr() method in the following line, you extract everything from char-
acter position fileNameStart right up to the end of the string. Remember that the substr() method
accepts two parameters, namely the starting character you want and the length of the string you want
to extract, but if the second parameter is missing, all characters from the start position to the end are
extracted.
You then add the fi le name into the array, the length property of the array providing the next free
index position.
You'll now turn to look collectively at the frame pages, namely ch08_examp2_a.htm , ch08_examp2_b
.htm , ch08_examp2_c.htm , and ch08_examp2_d.htm . In each of these pages, you create a form called
form1 .
<form name=”form1” action=”“>
<textarea rows=”10” cols=”35” name=”txtaPagesVisited”></textarea>
<br />
<input type=”button” value=”List Pages Visited”
name=”btnShowVisited” onclick=”btnShowVisited_onclick()” />
</form>
This contains the textarea control that displays the list of visited pages, and a button the user can
click to populate the <textarea /> element.
Search WWH ::




Custom Search