If your Website consists of frames, then the frame-set should be
loaded first, else the site may lose some formatting and contents. This script became
necessary for me when for one of my sites, Yahoo! listed the wrong file as the opening
page (welcome.html), leaving my visitors without any navigational aid. Thus, I needed a
script that would automatically redirect this page (and every other page for that
matter) in such a way that it would open in the proper frame. That is redirect them to the
HTML file containing the frame-set (index.html for my site).
size="2">
First you need code
to test if welcome.html has opened in a frame or not. If not, it’s to be redirected
to index.html. This can be easily done by placing the following code in the header of the
file welcome.html.
face="Arial" COLOR="#000000" size="2">This code checks if self.location is same as
parent.location, then load index.html, passing the name of the file (welcome.html in this
case) as a parameter.
Index.html contains the code where all the wizardry takes place. If you
want to force your visitors to the first page, then index.html need not be anything
special–just your usual frame-set HTML. In fact, you need not even pass the calling
file name as parameter, but if you want the calling file (welcome.html) to open in one of
the frames then you’ll have to script your frame-set, as shown below rather than hard
code it.
Your index.html
should contain just the above code. Note that all the statements in front of each
document.write should be in a single line. The first two document.writes are
straightforward. The third contains a conditional statement which provides the correct
file name.
" ‘,
(location.search?location.search. substring(1):"home"), ‘.html"
(Pay attention to the " ‘ and , as you type.)
It says that if
location.search is not a null statement, then use location.search.substring(1)–this
will be the name of the calling file (welcome) if index.html has been called from
welcome.html. But if location.search is null, then use home, that is, index.html is opened
directly. Both location.search.substring(1) and home are prefixed to the extension HTML,
resulting in the correct name of the file to be opened in the frame named
"main".