Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
this is the code that comes in head section and it will automatically refresh the whole page in 1 min as i put 6000 in the code below

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


is there any way for example, when there's 10 seconds left to refresh the page then, a button will display and say "Click here to reset timer" and it will reset that timer to 1 min again?

[Re-post of previous question — SA]
Posted
Updated 30-Jan-15 17:01pm
v3
Comments
Sergey Alexandrovich Kryukov 30-Jan-15 23:00pm    
Please don't re-post; this is considered as abuse. You could edit your previous answer and add appropriate comments if you could not use existing answers.

You ignored my last comment (good or not) where I tried to add an answer to your last question, then you repeated what you already wrote before. You did not reply if you tried the advice or not. If you wanted help, you would keep asking. To me, it just seems that you don't want to pay appropriate effort to write your code. Please do appropriate steps to solution, instead of re-posting.

—SA
Member 10749093 30-Jan-15 23:19pm    
you didn't help me in my last post even i tried to explain it to you many times. and i don't know if i can accept my last post as bad or not instead of accept it as solved. so if you don't know, and you can't help me, stop answering any of my posts. it's not your business how many times i post it. if it's abuse then let moderators do their own job by taking the right action.
Sergey Alexandrovich Kryukov 31-Jan-15 0:22am    
Please check yourself and start acting responsibly.

You ignored my help and did not ask further questions, but it's up to you. I cannot promise you to not answering your posts because it would be hard to remember you. But first of all, this is plain rude. Most of us play according to common rules, because they keep community together. If you want to say that you don't want that, you are free to claim that.

Not only "not your business" is extremely rude, but this is a plain false statement. Let me inform you: the site is primarily moderated by the efforts of the whole community, according to automatically supported voting and abuse reporting rules.

—SA

Here is the idea: if you use setTimeout, before the expiration time you can cancel it on the same timeout object using clearTimeout. Here is how:
http://www.w3schools.com/jsref/met_win_cleartimeout.asp[^].

Apparently, when the timeout is wound up and before expiration your button's click handle should get visible, access that timeout object (named myVar in the code sample referenced above) and call clearTimeout(myVar); then it would be good to hide this button.

I hope you know how to handle button clicks and hide/show elements. If something of that is a problem, all you have to do is to ask in an appropriate way.

—SA
 
Share this answer
 
Comments
Avik Ghosh22 31-Jan-15 1:27am    
5!
Sergey Alexandrovich Kryukov 31-Jan-15 3:00am    
Thank you, Avik.
—SA
 
Share this answer
 
Comments
Member 10749093 30-Jan-15 23:51pm    
thanks for your answer. but i am not asking how to refresh a page. i am asking about "when there's 10 seconds left to refresh the page then, a button will display and say "Click here to reset timer" and it will reset that timer to 1 min again"
Avik Ghosh22 30-Jan-15 23:58pm    
ok ..
XML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>



</head>
<body>
    <form id="form1" runat="server">
    <div id="myCounter">


</div>
        <asp:Button ID="btn" runat="server" OnClientClick="setTimeout('display()', 100)" />
        <asp:TextBox id="ee" runat="server"></asp:TextBox>

    </form>

    <script type="text/javascript">

        var milisec = 0
        var seconds = 30
        document.getElementById("myCounter").innerHTML = '30';

        function display() {

            if (milisec <= 0) {
                milisec = 9
                seconds -= 1
            }
            if (seconds <= -1) {
                milisec = 0
                seconds += 1
            }
            else
                milisec -= 1
            document.getElementById("myCounter").innerHTML = seconds;
            setTimeout("display()", 100)
        }
        display()

    </script>

</body>
</html>
 
Share this answer
 
Comments
Member 10749093 31-Jan-15 0:42am    
thanks for your answer Avik, but your code is only a good countdown timer but it doesn't refresh the page automatically and there's no button to reset the timer back to 60 seconds again without refreshing the page
Sergey Alexandrovich Kryukov 31-Jan-15 0:59am    
You are right. The problem of cancellation of the timeout is not solved here. As you know, I also did not pay attention for this aspect when answered this question for the first time, even though you formulated this problem in first place. It happens. Well, just... patience. Finally, I answered to this part of the question in some more detail.
—SA
Member 10749093 31-Jan-15 8:45am    
Thanks for your time Avik appreciate it, but i have solved this by myself.
Avik Ghosh22 31-Jan-15 10:42am    
good..

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