• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 4. Frames, Frames, and More Frames > Loading Multiple Frames at Once

Loading Multiple Frames at Once

It just takes a single link with a target attribute to change the content of a frame; that's simple HTML. To change the content of multiple frames with one click, you need JavaScript. Script 4.27 loads in the frameset, and Scripts 4.28 (detailed below), 4.29, and 4.30 update both the left and content frames simultaneously, as shown in Figures 4.12 and 4.13.

Figure 4.12. The page looks like this initially.


Figure 4.13. But When a link is clicked, both frames have changed.


Script 4.28. The initial navigation page…


To load multiple frames at once:

  • 								function setFrames(newPage) {
    								parent.content.document.location. href = "frame" + newPage + ".html"
    								document.location.href = "left" + newPage +".html"
    								}
    							
    
    					  



    This function is passed the variable newPage, which you then use to build the location of the two frames to be loaded. The content frame gets reset by changing the value of parent.content.document.location.href, and the left (current) frame is reset by changing the value of document.location.href.

Script 4.29. can turn into the second navigation page…


For example, when setFrames('8b') is called, the content frame is reset to "frame8b.html" ( Script 4.32 ) and the left frame is reset to "left8b.html" ( Script 4.29 ). Calling setFrames('8a') resets the content frame to "frame8a.html" ( Script 4.31 ) and the left frame to "left8a.html" ( Script 4.28 ), and setFrames('8c') resets the content frame to "frame8c.html" ( Script 4.33 ) and the left frame to "left8c.html" ( Script 4.30 ). In each case, the left navigation page shows what page is currently being displayed in the content frame, and does not allow the user to choose that option.

Script 4.30. or even the third navigation page.


Tip

If you want to load more than two frames simultaneously, just add them to the list. In other words, you would have to add another line specifying a value of document.location.href for each frame that you want to add. And if you want to change two frames, neither of which is the current frame, just follow the model in the step above, but specify both locations starting with the parent object.


Script 4.31. The initial content page…


Script 4.32. turns into the second content page…


Script 4.33. and the third content page.


  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint