One of the most common questions regarding JavaScript is how to change two frames at once. Although frames are becoming more and more unpopular among professional web developers, this question is still a hot topic. Of course, JavaScript can come to the rescue. A function expects the names or indexes of the two frames, and of course the two URLs to load. Since the individual frames are changing during the course of the application, this function should be placed in the frameset document: The Frameset with the JavaScript Function (frameset.html)
The left frame in this example is the navigation frame; the right frame is the content frame. When a link in the navigation frame is being clicked, both frames change, since every page in the right frame has an associated navigation page (with the current page highlighted) for the left frame. The Frameset with the Navigation (frame1a.html)
A more general approach does not limit the number of frames to two, but just accepts an arbitrary number of frame names and URLs: The Frameset with the More Flexible JavaScript Function (frameset.html; excerpt)
The file frameset.html in the download archive contains both versions of changeFrames(), with the less flexible one within a JavaScript comment. Tip Of course, this example works best if users without JavaScript are not excluded. So one approach would be to load a new page in the content frame, but use JavaScript to change the left frame as well, if the browser supports it: <a href="frame2b" target="content" onclick="top.changeFrames('navigation', 'frame1b.html', 'content', 'frame2b.html'); return false;">Frame 2</a>
|