Click here to Skip to main content
15,909,822 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am creating a web page which will automatically refresh for every 5 minutes by default. In the page provide an option for the user to enter the time duration in which page should refresh. Say if user enters 10 mins. then page should refresh every 10th minute. If user enters 0 the page should not refresh.
Posted

1 solution

Try the below approach.

XML
<html>
<head>
<title> Reload  the Page</title>
    <script type="text/javascript">


    function ref2()
    {
     var UserTime = document.getElementById("txttime").value;
      window.name = UserTime;
        ref1();

    }

    function ref1()
    {
    var time=window.name;

    if(time!="" && time!=0)
    {
    time=time*1000*60;
    setTimeout("location.reload();",time);
    alert("page reload after the " + window.name + " mins");

    }
    else if(time=="")
    {
     time=5*1000*60;
     setTimeout("location.reload();",time);
     alert("Default Reload 5 mins");

    }
    document.getElementById("txttime").value = window.name;
    }
    </script>
</head>
<body onload="return ref1()">
    <form id="form1" runat="server">
    <div>
    <table>
    <tr>
    <td>Enter the time:</td><td><input type="text" id="txttime" /></td></tr>
    <tr><td align="center"><input type="button" value="enter" id="bttme" onclick="return ref2()"; /></td></tr></table>
    </div>
    </form>
</body>
</html>
 
Share this answer
 
Comments
keerthana.k 13-Aug-12 6:33am    
thank you so much can you explain what is window.name

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