Go Back   Dynamic Drive Forums > General Coding > JavaScript
Search Dynamic Drive Forums:

Reply
 
Thread Tools Search this Thread
  #1  
Old 12-25-2005, 11:13 AM
KE5EHI KE5EHI is offline
Junior Coders
 
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!
Reply With Quote
  #2  
Old 12-25-2005, 08:05 PM
jscheuer1's Avatar
jscheuer1 jscheuer1 is offline
No Kidding?
 
Join Date: Mar 2005
Location: SE PA USA
Posts: 19,000
Thanks: 19
Thanked 1,135 Times in 1,121 Posts
Blog Entries: 3
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.
__________________
WWWWWWWWWWWW
- John
________________________

Really Show Your Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
Reply With Quote
  #3  
Old 12-27-2005, 01:42 AM
KE5EHI KE5EHI is offline
Junior Coders
 
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!
Reply With Quote
  #4  
Old 12-27-2005, 01:46 AM
KE5EHI KE5EHI is offline
Junior Coders
 
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.
Reply With Quote
  #5  
Old 12-27-2005, 04:58 AM
jscheuer1's Avatar
jscheuer1 jscheuer1 is offline
No Kidding?
 
Join Date: Mar 2005
Location: SE PA USA
Posts: 19,000
Thanks: 19
Thanked 1,135 Times in 1,121 Posts
Blog Entries: 3
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);
__________________
WWWWWWWWWWWW
- John
________________________

Really Show Your Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
Reply With Quote
  #6  
Old 12-27-2005, 09:16 AM
KE5EHI KE5EHI is offline
Junior Coders
 
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.
Reply With Quote
  #7  
Old 12-27-2005, 10:15 AM
KE5EHI KE5EHI is offline
Junior Coders
 
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
Reply With Quote
  #8  
Old 12-27-2005, 10:45 AM
KE5EHI KE5EHI is offline
Junior Coders
 
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.
Reply With Quote
  #9  
Old 12-27-2005, 06:11 PM
jscheuer1's Avatar
jscheuer1 jscheuer1 is offline
No Kidding?
 
Join Date: Mar 2005
Location: SE PA USA
Posts: 19,000
Thanks: 19
Thanked 1,135 Times in 1,121 Posts
Blog Entries: 3
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>
__________________
WWWWWWWWWWWW
- John
________________________

Really Show Your Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
Reply With Quote
  #10  
Old 12-27-2005, 11:49 PM
KE5EHI KE5EHI is offline
Junior Coders
 
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.
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:27 AM.

Home - Contact Us - Archives - Link to DD - Top 

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.