Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you refresh page on entry? 2

Status
Not open for further replies.

meeble3

Programmer
Nov 8, 2004
52
GB
Hello,

Is there a way to refresh a page as soon as you go to it then refresh every 5 minutes.

Thanks

James
 

You'd have to use a cookie-based solution IMHO... otherwise every time the page refreshed, it would refresh itself again (because it had just refreshed, and the refresh code would kick in, etc etc ad infinitum).

Dan


The answers you get are only as good as the information you give!

 

A meta refresh would not work, unless you wrote it out dynamically (otherwise you would suffer from the problem I described above).

And if you have scripting enabled to write the meta tag out, why not just use "document.location=" instead?

Dan


The answers you get are only as good as the information you give!

 
well...

you could use a meta-refresh for the five minute aspect.
and you could have onload=window.location=reloadPage()

and then in reloadPage() test for an occurrance of "?" in the url. if there is no "?", window.location = this.html?r or something.

ugly as sin, but it would work.

*cLFlaVA
----------------------------
[tt]a frickin' twelve-gauge, what do you think?[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
If you have any graphics on the page, and someone connects with a slow dialup connection, they'll never get to see the whole page load. As well, if you reload the page every 5 seconds, what's going to happen when someone tries to scroll down and see what's at the bottom of the page? Will they ever be able to do that? Sounds like a recipe to keep people away from your website. If you have one item that you want to refresh, why not put it in an iframe and just refresh that as you wish (though if it takes more than 5 seconds to reload, the viewer will never be able to see the information there)?

Lee
 
Lee, he wanted every 5 minutes, not seconds.

James, what I don't understand is why on earth you'd need the page to reload the instant it loads?

Adam

Pedro offers you his protection
 

CLFlaVa,

You've got a good point there. Adding a parameter to the URL would be another way of achieveing this without the use of cookies.

Dan
 
If you just want to refresh a certain part of your web page, the best way to do it would probably be to either use an IFrame like Lee suggest or use the XMLHTTP object to fetch the page behind the scenes and update the content on the page. Much less blinking that way.

Adam

Pedro offers you his protection
 
That's just an Idea but you can try something like this (I didn't try it so there may still errors):

<HTML>
<SCRIPT language = "javascript">
var timeIsOut = false;
function reloadPage(){
var newLocation = window.location + '?reloaded=true';
if(!reloaded || timeIsOut)
window.location = newLocation;
else
setTimeout('reloadPage()', 5 * 60);
timeIsOut = true;
}
</SCRIPT>
<BODY onLoad = "javascript:reloadPage();">
...
</BODY>
</HTML>


So.. not sure that's correct and not sure that's what you wanted. You do not need to use cookie. Just When you are refreshing the page just indicates that you have already done it with a variable that you gives with the url (reloaded in my example). The timeIsOut variable indicates that the next time the reloadPage function is called (after five minuts because of the setTimeout instruction) it will reload the page even if the reloaded variable is true

Hope this will help you
 
I just had a great original idea. If you passed a flag in the querystring after you reload, you could reload the page if the flag isn't there and you wouldn't need to use cookies! Damn I'm smart!

Adam

Pedro offers you his protection
 
I would pass a flag in the querystring and then in the onreload check for it. And I want a star for that.

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Hello meeble, after doing extensive research and thinking long and hard on this subject, I think that cookies or some querystring manipulation would do the trick.

-kaht

Do the chickens have large talons?
 
I've put together a solution in the past that used an extra parameter (like a query string). It required the user to have javascript installed, because onload I would check the location to see if there was a '?' in there... if not... redirect to the same page with a parameter.

Now... unlike the other solutions here... I use the word parameter.

Jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top