使用javascript刷新页面 [英] refresh the page using javascript

查看:97
本文介绍了使用javascript刷新页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个默认情况下每5分钟自动刷新一次的网页.在页面中,提供一个选项供用户输入页面刷新的持续时间.假设用户输入了10分钟.然后页面应每10分钟刷新一次.如果用户输入0,则页面不会刷新.

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.

推荐答案

尝试以下方法.

Try the below approach.

<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>


这篇关于使用javascript刷新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆