Maybe you want to open more than one window at the same time (and really run the risk of seriously annoying the person browsing your site). You can do that with just a small addition to Script 6.4; you need to add a loop that opens a window every time it goes through the loop, as shown in Script 6.5 .
| 1. | document.links[i].onclick = newWindows; In the newWinLinks() function, we've changed the line that was in Script 6.4 to call the newWindows() function, since we're opening more than one window. |
| 2. | function newWindows() { var bookTitles = new Array("dw8", "js6e","ppt"); Begin by creating a new function that will handle opening the multiple windows. Next, create a new array called bookTitles , and populate it with the names of the windows. |
| | |
| 3. | for (var i=0; i<bookTitles. length;i++) { var imgName = "../images/" + bookTitles[i] + ".jpg"; var winName = bookTitles[i] + "Win"; var bookWindow = window.open (imgName,winName,"width=135, height=170"); } The loop will execute as many times as there are elements of the bookTitles array, using the length property. The imgName variable contains the constructed path of the images. The winName variable gets the current value of bookTitles and adds Win to it. The bookWindow variable opens the window with the image, adds the window's name , and specifies the window size . The result of all this looping is shown in Figure 6.6 . Figure 6.6. Clicking the link opened all three child windows; the placement was determined by the browser. In this case, Safari opened all three windows on top of one another, and we moved them for clarity's sake. |