A couple of questions:
几个问题:
-
I've never really used JS listeners other than
onclick
andonkey
events, so I wondered if someone could help me with what I need in order to reload the page every X seconds?我从来没有真正使用过除了onclick和onkey事件之外的JS监听器,所以我想知道是否有人可以帮我解决我需要的每隔X秒重新加载页面的问题?
-
Secondly, the page contains bare minimum, literally just one input box. Do I still need to include the html
head
andbody
?其次,页面包含最小的,实际上只有一个输入框。我还需要包含html头部和身体吗?
4 个解决方案
#1
21
You don't need Javascript for this simple function. Add in the page header:
这个简单的功能你不需要Javascript。添加页眉:
<meta http-equiv="Refresh" content="300">
300 is the number of seconds in this example.
300是此示例中的秒数。
#2
19
To reload the page after 5 seconds (5000 milliseconds) using JavaScript, add the following to the bottom of the page:
要使用JavaScript在5秒(5000毫秒)后重新加载页面,请将以下内容添加到页面底部:
<script type="text/javascript">
setTimeout(function () { location.reload(true); }, 5000);
</script>
As Greg Hewgill notes, you can also accomplish this with the meta refresh tag:
正如Greg Hewgill指出的那样,您还可以使用元刷新标记完成此操作:
<meta http-equiv="Refresh" content="5">
Strictly speaking, you do still need <html>
and <body>
tags. Some browsers may render the page correctly without them, but your are safest to include them.
严格来说,你仍然需要和标签。有些浏览器可能会在没有它们的情况下正确呈现页面,但最安全的是包含它们。
#3
1
use a timer: http://www.elated.com/articles/javascript-timers-with-settimeout-and-setinterval/ and usee ajax to reload if it is dynamic
使用计时器:http://www.elated.com/articles/javascript-timers-with-settimeout-and-setinterval/并使用ajax重新加载,如果它是动态的
#4
0
To your second question, ye you definitely do!!
对于你的第二个问题,你绝对做到了!
Toy your first question check this out:
玩你的第一个问题检查出来:
http://www.javascriptkit.com/script/script2/autofresh.shtml
http://www.javascriptkit.com/script/script2/autofresh.shtml
Or this to do it without javascript:
或者这样做没有javascript:
http://webdesign.about.com/od/metataglibraries/a/aa080300a.htm
http://webdesign.about.com/od/metataglibraries/a/aa080300a.htm
It does what you asked and is very easy to configure!
它做你所要求的,并且很容易配置!
#1
21
You don't need Javascript for this simple function. Add in the page header:
这个简单的功能你不需要Javascript。添加页眉:
<meta http-equiv="Refresh" content="300">
300 is the number of seconds in this example.
300是此示例中的秒数。
#2
19
To reload the page after 5 seconds (5000 milliseconds) using JavaScript, add the following to the bottom of the page:
要使用JavaScript在5秒(5000毫秒)后重新加载页面,请将以下内容添加到页面底部:
<script type="text/javascript">
setTimeout(function () { location.reload(true); }, 5000);
</script>
As Greg Hewgill notes, you can also accomplish this with the meta refresh tag:
正如Greg Hewgill指出的那样,您还可以使用元刷新标记完成此操作:
<meta http-equiv="Refresh" content="5">
Strictly speaking, you do still need <html>
and <body>
tags. Some browsers may render the page correctly without them, but your are safest to include them.
严格来说,你仍然需要和标签。有些浏览器可能会在没有它们的情况下正确呈现页面,但最安全的是包含它们。
#3
1
use a timer: http://www.elated.com/articles/javascript-timers-with-settimeout-and-setinterval/ and usee ajax to reload if it is dynamic
使用计时器:http://www.elated.com/articles/javascript-timers-with-settimeout-and-setinterval/并使用ajax重新加载,如果它是动态的
#4
0
To your second question, ye you definitely do!!
对于你的第二个问题,你绝对做到了!
Toy your first question check this out:
玩你的第一个问题检查出来:
http://www.javascriptkit.com/script/script2/autofresh.shtml
http://www.javascriptkit.com/script/script2/autofresh.shtml
Or this to do it without javascript:
或者这样做没有javascript:
http://webdesign.about.com/od/metataglibraries/a/aa080300a.htm
http://webdesign.about.com/od/metataglibraries/a/aa080300a.htm
It does what you asked and is very easy to configure!
它做你所要求的,并且很容易配置!