Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi. can sme on please help me to make this javascript code correct

XML
<script type="text/javascript">
setTimeout('window.location.href=window.location.href;', 300000);
</script>


this code will refresh the page automatically in 300000 milliseconds which is 5 mins.

so my page contains like this below

XML
<script type="text/javascript">
setTimeout('window.location.href=window.location.href;', 1080000);
</script>

<div id="norefresh">page refresh in 5 mins click "HERE" to not refresh</div>


so i want to make it when like 1 min left to refresh that text in id norefresh must be showing like that to cancel page refresh. thank you.
Posted
Comments
Sergey Alexandrovich Kryukov 27-Jan-15 21:04pm    
What is the exact purpose of your refresh? Did you try to use setTimeout?
—SA

1 solution

Please see my comment to the question. Please see the explanation of the use of setTimeout here:
http://stackoverflow.com/questions/4644027/how-to-automatically-reload-a-page-after-a-given-period-of-inactivity[^].

(Just ignore the aspect of "period of inactivity" and the mouse/keyboard binding code shown.)

The full answer depends on the purpose of your refresh; in general case, there are other methods. Typically, auto refresh is done to implement pull technology, which is a bad thing, a result of the lack of server push.

See my past answer and the article referenced below:
http://en.wikipedia.org/wiki/Pull_technology[^],
http://en.wikipedia.org/wiki/Server-push[^],
Application 'dashboard' for website accounts[^].

—SA
 
Share this answer
 
Comments
Member 10749093 27-Jan-15 23:12pm    
Thanks for answer, Sergey, my auto refresh code above is fine. it does refresh he whole page in 5 mins as i modified . but my purpose of my question is that div id norefresh.

for example, when 1 min left to refresh from that 5 min, then that text in that id norefresh must show some text saying "page will refresh in 1 min click "HERE" to not refresh" so when you clicked on that text timer must set to 5 mins again and it must be started . hope you understand.
Sergey Alexandrovich Kryukov 27-Jan-15 23:28pm    
So complicated... why doing all that..? Wouldn't it only confuse the user? Well, you need to call
clearTimeout.

Are you going to accept the answer formally now?

—SA
Member 10749093 28-Jan-15 0:18am    
as i am not that good with javascript but i don't think it's that complicated.

that text will only show that last 1 min left to refresh so user can click on it to reset timer to 5 mins again and it will not refresh the chat.

well, i don't know if i accept the answer because it didn't help me. thanks for your time and for your answer.
Sergey Alexandrovich Kryukov 28-Jan-15 2:12am    
Of course I didn't mean complicated code. I don't understand what else you are missing (especially if you think that it's not that complication), but you can ask some follow-up questions. The problem is fairly simple.
—SA
Member 10749093 28-Jan-15 2:31am    
i will try to explain 1 more time to make it clear for you. if you can help me with it i will be really grateful

this is my page:

<html>
<head>
<script type="text/javascript">
setTimeout('window.location.href=window.location.href;', 1080000);
</script>
</head>

<body>

<div id="norefresh">HERE SHOW COUNTDOWN TIMER WHEN 1 MIN LEFT AS TEXT. CLICK HERE TO RESET TIMER TO 5 MINS TO PREVENT REFRESHING THE PAGE</div>

</body>

</html>

hope you understand from what i wrote above . on div id norefresh it must show countdown timer as text only like, "this page will refresh in 60 seconds" and that countdown as text is going like , "60, 59, 58, 57, 56, 55, 54 to 0 then refresh the page if user didn't click on that text "CLICK HERE TO RESET TIMER TO 5 MINS TO PREVENT REFRESHING THE PAGE" . but if user clicked, then reset timer to 5 mins and it's not going to refresh the page

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900