Auto Refresh Your Page

If you are looking for a source code to have an Auto Refresh function to your projects then you are at the right place. There are many sites that have this function to refresh their page automatically. So, let's work on it.

Source Code:

This script that you can edit the refreshing time of your page.
  1. //enter refresh time in "minutes:seconds" Minutes should range from 0 to inifinity. Seconds should range from 0 to 59
  2. var limit="0:30"
Full Script
  1. <script>
  2. //enter refresh time in "minutes:seconds" Minutes should range from 0 to inifinity. Seconds should range from 0 to 59
  3. var limit="0:30"
  4.  
  5. var doctitle = document.title
  6. var parselimit=limit.split(":")
  7. parselimit=parselimit[0]*60+parselimit[1]*1
  8.  
  9. function startTo_Refresh(){
  10. if (parselimit==1)
  11. window.location.reload()
  12. else{
  13. parselimit-=1
  14. curmin=Math.floor(parselimit/60)
  15. cursec=parselimit%60
  16. if (curmin!=0)
  17. curtime=curmin+" minutes and "+cursec+" seconds left until your page refresh!"
  18. else
  19. curtime=cursec+" seconds left until your page refresh!"
  20. document.title = doctitle + ' (' + curtime +')'
  21. setTimeout("startTo_Refresh()",1000)
  22. }
  23. }
  24.  
  25. if (window.addEventListener)
  26. window.addEventListener("load", startTo_Refresh, false)
  27. else if (window.attachEvent)
  28. window.attachEvent("load", startTo_Refresh)
  29. </script>

Output:

As you can see the image below. We set the refreshing time in "0:30" seconds. Result And, that's it!!! You can insert this script to have auto refresh on your page. So what can you say about this work? Share your thoughts in the comment section below or email me at [email protected]. Practice Coding. Thank you very much.

Add new comment