|
April 5, 2000 Forcing Frames Tips: April 2000
Yehuda Shiran, Ph.D.
|
|
If your Web site is based on frames, and you don't want the user to be able to load an inner page in a full window, you can rebuild the frame-setting document when the user attempts to load such a page. First, take a look at the following HTML document:
This document is named canvas.html. The upper and left frames are used for navigation purposes, while the main frame displays the actual content of the site. canvas.html initially loads frame3.html as the content page, but other documents can be loaded in that frame as well. Let's assume the user loads a document named frame4.html in the main frame. Everything looks great. We now have a frame-setting document named canvas.html, and three child frames named frame1.html, frame2.html, and frame4.html.
But what happens if the user attempts to load frame4.html in a separate window? We need to force the frames. First, we'll add a simple script to the
frameNum needs to be replaced with the index of the target frame. Use 0 (the first frame) for frame1.html, 1 (the second frame) for frame2.html, and 2 (the third frame) for frame3.html and frame4.html. For example, in frame4.html the script would be:
Now let's see the new version of canvas.html:
We start by assigning the three default frames, frame1.html, frame2.html, and frame3.html to three variables, ar0, ar1, and ar3, respectively:
These three files are the the basis of the the frame set. Any subsequent change will be on top of these three initial frames. Then, we extract the location.search string:
This string begins after the question mark at the URL. In the example above, we added a string to the canvas.html URL:
The string location.search will be equal to frame4.html&2 in this case. In order to find the frame number at the end of this string, we use the String's indexOf() method to get the &'s position:
And we take the substring starting just after the &, and ending at the end of the URL:
Now that we know both the frame number and the file name, we can assign the file to the frame:
Learn more about frames in Column 36, JavaScript and Frames, Part I .
People who read this tip also read these tips: Look for similar tips by subject: |