Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Jun 2002
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Page reload, infinite loop?

    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 -------------- -->
    </script>

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


    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'?

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    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.

    OR

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

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    There's a third solution as well - don't use a frameset. You don't really need it.

  • #4
    New Coder
    Join Date
    Jun 2002
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

    OR

    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?

  • #5
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    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


    <script>
    if (document.location == top.document.location)
    document.location = "index.htm"
    </script>

    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.

    http://www.huntingground.freeserve.c...mes/loader.htm


    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

  • #6
    New Coder
    Join Date
    Jun 2002
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I had a thought. Why not just add:

    <script>
    if (document.location == top.document.location)
    document.location = "index.htm"
    </script>

    ...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?

  • #7
    New Coder
    Join Date
    Jun 2002
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •