frames.js
- Practical use
Forced frame loading
- Version requirement
JavaScript 1.1
- Functions
keepIn(),keepOut()
This source file contains only two functions. One keeps your documents in a particular frameset. The other keeps your documents out of them. frames.js requires multiple HTML pages for its examples. For example, try to load ch06\frameset.html in your browser. This file is a frameset with two frames. One of the frames has file frames.html as the source. frames.html utilizes frames.js to ensure that frames.html is always loaded in the top window. That’s why loading frameset.html gives you the results shown in Figure 6.10 and Figure 6.11 (the browser loaded frames.html ).
Conversely, those who want to make certain that their files aren’t loaded unless they are in a particular frameset can use frames.js as well. Check out Figure 6.10, which shows what happens when you try to load ch06\frames2.html. You’ll get an alert stating the frameset violation, then the browser loads the corresponding frameset containing frames2.html. You can see this in Figure 6.11.

Figure 6-10. Busted by the frameset police

Figure 6-11. That’s better
The code to accommodate this functionality is short and sweet.
Function keepOut() compares document URL in the top window with the document URL of the current ...