Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Reload external page in frame, no-cache?

  1. #1
    Join Date
    Aug 2005
    Location
    Oklahoma
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Reload external page in frame, no-cache?

    I'm working on a site that is going to be loading external pages into a frame. These are going to be both text and graphics that update as quick as 5 minutes. My question is how do I get the frame to refresh itself and whatever content is currently displayed?

    I'm not good on javascript, but I was playing with a script I found that is pretty much this (in the frameset index.htm page):

    Code:
    setTimeout('refresh()', 300000);
    
    function refresh() {
    window.frames['main'].location.replace();
    setTimeout('refresh()', 300000);
    This code reloads the index.htm into the 'main' window, so I get two menus (top and side). How do I make it only refresh the content in the 'main' window? Also, is there a way to add something in there to not cache the image/text?

    Thanks!

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Put the location url for the content:

    Code:
    setTimeout('refresh()', 300000);
    
    function refresh() {
    window.frames['main'].location.replace('here');
    setTimeout('refresh()', 300000);
    Example:

    Code:
    window.frames['main'].location.replace('somepage.htm');
    Be sure to include the single quotes (') around the page name.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Aug 2005
    Location
    Oklahoma
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Right, but is there a way to make it load whatever is in that window? It's going to have numerous (probably around 20ish) pages and I'm trying to get a script on the index.htm frameset page that will refresh that frame not matter what is in it. Can I point the refresh to the name of the frame instead of a URL?

    Thanks!

  4. #4
    Join Date
    Aug 2005
    Location
    Oklahoma
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    ...or somehow make it read the url that is loaded in that frame. The images and text are going to be coming from an external source, and they range from .gif to .txt and the 'main' frame itself doesn't always load a .html file, sometimes it just loads a .gif or .txt. Hope that makes sense.

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    You can give this a shot, worked here in local testing:

    Code:
    function refresh() {
    window.frames['main'].window.location.replace(window.frames['main'].window.location);
    setTimeout('refresh()', 300000);
    }
    
    setTimeout('refresh()', 300000);
    It would be better if we knew the URL in question, how are these determined? Is it the result of the user clicking on a link? If so, we code grab the URL of the href of each link at the time it is clicked and store it in a variable to be used:

    Code:
    window.frames['main'].window.location.replace(here);
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #6
    Join Date
    Aug 2005
    Location
    Oklahoma
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks! I'm gonna give that a try in a few minutes. I haven't put the site up yet (just starting it), but if that doesn't work, I'll post it.

    In short, there's 3 frames: top, side, main

    Top links to side, side links to main

    Side is composed of links to pages or images (ie. http://www.whatever.com/page.htm or http://www.whatever.com/image.gif), that load into the main frame and those pages/images are on an external server (not tied in with me). Those images are updated in 5-10min intervals and I'm trying to get my site to refresh them (by refreshing the frame itself, since I'm going to have a lot of links to manage).

    I'll let you know here in a bit if that code works.

  7. #7
    Join Date
    Aug 2005
    Location
    Oklahoma
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Okay, doesn't seem it worked. I uploaded the site:
    http://www.towpc.com/ke5ehi/wx/

    I've put a graphic for the 'main' window that updates every 10 minutes, and I've changed the refresh timer to 25 seconds (for testing). Give it a looksy and see what might be wrong when you got a minute. My goal, again, is for anything loaded in the 'main' window to be refreshed every 5 minutes. If I can tack on a script on each link for another script to refresh it, that would work too (as long as it doesn't try to refresh the last page with the script and when a page is loaded that doesn't need to be refreshed, it refreshes it back to the last refreshable item).

    I'm getting tired of typing 'refresh', heh

  8. #8
    Join Date
    Aug 2005
    Location
    Oklahoma
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Wait a sec... it worked when I reloaded the page and the main.htm was in the main window, but it doesn't work when a graphic or page (ie SPC Main Page) is loaded.

  9. #9
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    That has to do with the security of a frame's content across domains. You didn't mention before (as far as I remember) that this would be off site content. My idea of keeping track of the URL works here though. The way to do that would be something like so:

    Code:
    <!-- Refresh 'main' window, 5min -->
    <script type="text/javascript">
    //Set theURL to the initial page for 'main'
    var resetVar, theURL="http://www.srh.noaa.gov/radar/images/DS.p19r0/SI.kinx/latest.gif";
    function refresh() {
    window.frames['main'].window.location.replace(theURL);
    resetVar=setTimeout('refresh()', 60*1000*5);
    }
    function reset(url){
    if (typeof url!=='undefined')
    theURL=url
    clearTimeout(resetVar)
    resetVar=setTimeout('refresh()', 60*1000*5);
    }
    reset();
    </script>
    Then on links to that frame that you wish to be updated use this type of syntax:

    HTML Code:
    <a href="info.htm" onclick="parent.window.reset(this.href);return true;" target="main">Page Info</a>
    On links that you would like to revert to the previous content after 5 minutes, use this syntax:

    HTML Code:
    <a href="info.htm" onclick="parent.window.reset();return true;" target="main">Page Info</a>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  10. #10
    Join Date
    Aug 2005
    Location
    Oklahoma
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks John, you rock! That's working except one issue. I've uploaded the site again (most of the links at the top don't work yet) so you can see.

    I've set the timer to 20 seconds for testing.

    When the site loads, the main page will refresh after 20 seconds. If you click on SPC Products from the menu, then click anything else in the SPC menu, it will reload the 'main.htm' after 20 seconds. I put the link code on the link under "Watch, Warning, Adv." named SPC: "Watches." When you click that link, it will load the watches image (http://www.spc.noaa.gov/products/watch/validww.png) and will reload that image every 20 seconds. But if you click say SPC: "WWA", after 20 seconds it will reload the 'Watches' graphic.

    How do I keep it so when a link is clicked that doesn't have the refresh onclick code, it won't reload the last image that was set to refresh?

    I hope this is making some sense. Most of the images that are loaded (ie http://www.spc.noaa.gov/products/watch/validww.png) need to be refreshed in 5 min intervals, but some of the pages (ie http://www.spc.noaa.gov) that are loaded into the main frame have their own refresh code on the page, so I don't have to make them refresh myself.

    Thanks again for the help, I'll make sure to mention ya in the credits.

Bookmarks

Posting Permissions

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