function initLinks() {
for (var i=0; i<document.links. length; i++) {
document.links[i].onclick = writeContent;
document.links[i].thisPage = i+1; }
The
initLinks() function begins in the same way as in
Script 5.8, by looping through the links on the page. Then, for each link, two things are set: the
onclick handler for that link, and a new property is added:
thisPage. The latter contains the page number to be displayed when that link is clicked, i.e., link 0 is "page 1", link 1 is "page 2", and so on. The
onclick handler in the loop sets every link to call the
writeContent() function when they're clicked.