Javascript自动页面刷新代码 [英] Javascript auto page refresh code

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

问题描述

这是head部分的代码,它会在1分钟后自动刷新整个页面,因为我在下面的代码中输入了6000



 <   script    类型  =  text / javascript < span class =code-keyword>>  
setTimeout('window.location.href = window.location.href;',6000);
< / script >





有没有办法,例如,当剩下10秒钟刷新页面时,会显示一个按钮并说点击这里重置计时器它会再次将该计时器重置为1分钟?



[重新发布 上一个问题 - SA]

解决方案

这是一个想法:如果你使用 setTimeout ,在到期时间之前你可以使用<$ c在同一个超时对象上取消它$ C> clearTimeout 。方法如下:

http://www.w3schools.com/jsref/met_win_cleartimeout.asp [ ^ ]。



显然,当超时结束并且在到期之前,按钮的单击句柄应该可见,访问该超时对象(名为 myVar in上面引用的代码示例)并调用 clearTimeout(myVar); 然后隐藏此按钮会很好。



我希望你知道如何处理按钮点击和隐藏/显示元素。如果这是一个问题,你所要做的就是以适当的方式询问。



-SA


http ://www.aspsnippets.com/Articles/Reload-Refresh-and-Redirect-Pages-using-Meta-Tags-in-ASP.Net.aspx [ ^ ] br />






http://forums.asp.net/t/1582832.aspx?how+to+refresh+asn + asp + net + page +自动+ + a +时间+间隔+ [ ^ ]


 <温泉n class =code-keyword><   html     xmlns   =  http://www.w3.org/1999/xhtml >  
< head runat = < span class =code-keyword> server >
< title > < / title >



< / head >
< body >
< 表格 id = form1 runat = server >
< div id = myCounter >


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

< / form >

< script 类型 = text / javascript >

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

函数display(){

if(milisec < = 0) {

milisec = 9

- = 1

}

< span class =code-attribute> if (秒 < = - 1) {

< span class =code-attribute> milisec = 0

+ = 1

}

else

milisec - = 1

< span class =code-attribute> document.getElementById(myCounter)。innerHTML = 秒;

setTimeout(display(), 100)

}

display()



< / script >

< / body & gt;
< / html >


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

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

解决方案

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


http://www.aspsnippets.com/Articles/Reload-Refresh-and-Redirect-Pages-using-Meta-Tags-in-ASP.Net.aspx[^]

or

http://forums.asp.net/t/1582832.aspx?how+to+refresh+asn+asp+net+page+automatically+in+a+time+interval+[^]


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


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

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