Does anyone here know how i could modify this java script code which automatically refresh a page due to the time interval you set.

I need assistance on how i can modify this code so it refreshes only once when the page is opened,


Auto Refresh Page with Time script
By JavaScript Kit (javascriptkit.com)
Over 200+ free scripts here!

//enter refresh time in "minutes:seconds" Minutes should range from 0 to inifinity. Seconds should range from 0 to 59
var limit="0:30"

if (document.images){
var parselimit=limit.split(":")
function beginrefresh(){
if (!document.images)
if (parselimit==1)
if (curmin!=0)
curtime=curmin+" minutes and "+cursec+" seconds left until page refresh!"
curtime=cursec+" seconds left until page refresh!"


Edited by Waado: correction

4 Years
Discussion Span
Last Post by JorgeM

What are you trying to achieve?
I can understand reloading a page every x seconds, but why would you display a page and then x seconds later reload the page just once?


i want to be able to auto update a picture profile which i normally use refresh button to acieve


Sorry, I'm still not understanding. Can you take me through what you want to happen step-by-step. No code.


Do you mean the picture is being uploaded without a postback and you want the picture to be updated automatically on the page once the upload is complete?

More info is needed, I agree with paulkd that you may want to tell us more about the process itself.


When i update my profile picture, i always need to click on refresh to get the new update, what i wanted to do is make the script just reload once when rediredted to the page so i donr need to click on refresh agai, this script works but it keeps refreshing in loop, i just need it to refresh once when the page is visited


Ok, so your problem is that you cant really track the number of times a page has been refreshed because anything you store in a javascript variable will be lost when the page is reloaded.

You can store a value in a cookie, or HTML5 localstorage.

There's another simplier option which will work the first time the page is opened. You can assign a value to window.name and that value can be accessed after a page reload unless the tab or window is closed..

here is an example you can try and you will see it will only reload the page 1 time after one second.

<!doctype html>
function beginrefresh(){
  window.name = "refreshed"
  var x = window.name
  if (x != "refreshed") {
  } else {
  document.write("Reloaded 1 time..")


Again, a better, more appropriate solution may be to save a value to a cookie and just read the cookie after the page refresh. If the value is there, do not reload the page again.

Same thing if you are interested in using HTML5 local storage, but with the local storage option, only the newer versions of browsers support it.

Edited by JorgeM


i have tried all you said but cant get it to work, can anyone help with a working example


The example i posted is a working example based on your description.

What isn't working about the example provided? It reloads the page one time after one second.


i assign a value to window.name 1, what do i put here document.write("Reloaded 1 time..") in Reloaded 1 time..


i assign a value to window.name 1

If you did that then you have to check to see if the value is 1 during the if..else statement.

what do i put here document.write("Reloaded 1 time..") in Reloaded 1 time..

nothing is required there... the point of that in my example was to show that the page was reloaded and the if..else statement's condition was FALSE when it ran on the second time, after the page refresh showing that the window.name value was still accessible and from that point on the statement would always be FALSE and the page would no longer reload.

Edited by JorgeM

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.