Search This Blog

Refresh Page Html/Java Scripts

Jul 29, 2012

Reload All By Itself

This one's nice and easy. I'll give you the code. Copy and paste it into the document you wish to reload. Once in there, change the number of seconds you wish the page to wait before starting the reloading process. This code goes in between the HEAD tags.


<META HTTP-EQUIV="refresh" CONTENT="15">
Right now, the command is set to reload every 15 seconds. I checked a couple of online sites and they were all set about the same. I found the sites displaying stock information were set to around five minutes or 300 seconds.
I don't have a refresh on this page because the darn thing would just keep refreshing and there's nothing on this page that will update.

Reload From A User's Click

I've seen this done a number of ways, but this is my favorite because it, again, forces the browser to load from the server. It is true that pages can become cached if they are reloaded a great many times, but I have had pretty good success with this. Here's the code:


<A HREF="javascript:history.go(0)">Click to refresh the page</A>
Rather than using a refresh command, I like to go to the history of the page and set it to zero. The zero is the current page since in JavaScript, lists (arrays) are numbered starting with zero. Here's the same effect in a button:


And the code:
<FORM>
<INPUT TYPE="button" onClick="history.go(0)" VALUE="Refresh">
</FORM>



Use the Full URL?

Again, it's possible that a page using the methods shown above can get cached and can stop reloading from the server. A Webmaster friend told me that if you simply set up a link to the current page but use the entire URL, the page would always reload from the server because the request starts at the domain. For example, the full URL of this page is:


http://anintrospectiveworld.blogspot.com/2012/07/refresh-page-htmljava-scripts.html
If you use that full URL in each of the elements above, you'll lessen the chance the page will cache. Thus, the Meta Refresh would become:
<META HTTP-EQUIV="refresh" CONTENT="5; URL=http://anintrospectiveworld.blogspot.com/2012/07/refresh-page-htmljava-scripts.html">
You would then change out the JavaScript formats above to simply go to the URL rather than looking at the history file. In fact, you could lose the JavaScript altogether and just make a simple A HREF link right to the current page. The trick is to use the full URL address so that the process starts at the very beginning.
Again, the effect is the same as you'll get with the code above. It just lowers the chance of the page getting stuck in cache.

No comments:

Post a Comment

 

Blog Archive