View Full Version : Page reload, infinite loop?

03-02-2003, 04:16 AM
Hi. I have a simple framed web site. The index.htm has:

<script LANGUAGE="JavaScript" TYPE="text/javascript">
<!-- Beginning of JavaScript -------------------
var locsrch = location.search
// -- End of JavaScript code -------------- -->

<frameset rows="282">
<frameset cols="155,*" border="0" frameborder="0" framespacing="0">
<frameset id="frm" rows="*,0" border="1" frameborder="1"
<frame name="frame" src="frame.htm">
<frame name="main" src="home.htm" scrolling="auto">

At the bottom of all pages is a simple <a href="home.htm"
target="main">Return to Home</a>. Recently I've been able to turn off the gripper feature of our domain name. So now I can tell people to access pages directly, as in http://www.wmich-astro.org/strehl.htm. Problem. If people then use 'Return to Home', they're not in a frame and thus miss all the links in the left side frame.

A thought. I'd like to add code to home.htm to detect the index.htm variable locsrch. If not present, reload index.htm. But if index.htm cannot load, how do I avoid an infinite loop in home.htm trying to load index.htm? Or is there a better way to 'Return to Home'?

Mr J
03-02-2003, 06:21 PM
There are two solutions to this problem

1) Change the target url of "Return to home" from home.htm to index.htm.

This will reload your frameset with both pages in the frames.


Use a script to load the parent frameset if the page is out of the frameset.

03-02-2003, 06:44 PM
There's a third solution as well - don't use a frameset. You don't really need it.

03-02-2003, 08:50 PM
Originally posted by Mr J
There are two solutions to this problem

1) Change the target url of "Return to home" from home.htm to index.htm.

This will reload your frameset with both pages in the frames.


2) Use a script to load the parent frameset if the page is out of the frameset.

1) Might have to, but home.htm is what you want if you're already framed.

2) That's what I was thinking. Testing for a variable found in index.htm and if not found, load index.htm. But what if the variable in index.htm somehow didn't load? Or index.htm itself can't load?

Maybe I'm worrying other nothing. But isn't there a way to have home.htm try to reload index.htm just once?

Someone suggested I get away from frames. In this case, no. The left frame file frame.htm has 40k worth of JavaScript code. Turning that into a webbot would overwork all page loads.

Had another thought. <a href="home.htm"
target="main">Return to Home</a>. What about adding a onclick=. If no frame "main" exists, then use index.htm?

Mr J
03-02-2003, 09:11 PM
Lets get this right .....

index.htm is the frameset page that creates your two frame frameset.

In "frame" frame.htm is loaded .... this is the navigation page.

In "Main" home.htm is loaded .... this is the home page.

In all other pages there is a link to take you back to the home page "home.htm" but if a page is accessed directly, selecting the "Home" link loads home.htm in a single window.

So .........

if the Home link was changed to load index.htm instead of home.htm the frameset would reload with frame.htm and home.htm in the respective frame.

This would give you the result you are after unless you go with a script that is placed in all pages to load the parent frameset

Here is a simple method

if (document.location == top.document.location)
document.location = "index.htm"

This script would be placed in all pages.

This would load the parent frameset with its default pages.

If you wanted the page to be loaded with the parent frameset and itself in the correct frame you need a different script.

The following link will take you an example on my site.


loader.htm is part of a two frame frameset but is not the default page.

Because I have given you the direct address the page will open in a window on its own.

A script in this page will detect this and immediately loads the parent frameset and reloads loader.htm into the main frame

Sorry if this sounds a bit confusing but take a look

03-03-2003, 06:37 PM
I had a thought. Why not just add:

if (document.location == top.document.location)
document.location = "index.htm"

...to the header of home.htm? Well, I tried it. Problem. Clicking [Return to Home] from a standalone web page launches another window. home.htm tries to load and the above code reloads index.htm. But any web page launched with a target="main" does NOT come up in that frame. And a simple home.htm#membership still reloads index.htm. Tried:

if (document.location == parent.document.location) document.location = "index.htm"

...and even...

if (typeof(parent.locsrch) != "string") document.location = "index.htm"

Same results. What's going on?

03-04-2003, 05:54 AM
Solved the problem!

When a <a href="home.htm" target="main">Return to Home</a> doesn't have a frame "main", it opens a new window. This new window is called, strangely enough, "main". So now any <a href="home.htm" target="main">Return to Home</a> will go to the window called "main", not the frame "main".

The solution is simple. In my index.htm, I added self.name="". Now I don't have to change all my pages, all the pages still load quick, and if home.htm is all by itself index.htm is loaded.

Try a page for yourself: http://www.wmich-astro.org/strehl.htm