每两分钟自动刷新一次页面吗? [英] Autorefresh A Page Every Two Minutes?

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

问题描述

如何每两分钟在asp.net中自动刷新页面?

How to Autorefresh a page every two minutes in asp.net?

推荐答案

自动网页刷新可以在ASP.NET(.aspx)网站中实现-页面,方法是在 header部分添加一些HTML代码.
您只需在标题"部分中添加以下代码行即可在ASP.NET网页中启用自动刷新.
Automatic web page refresh can be implemented in an ASP.NET (.aspx) web-page by adding some HTML code in the header section.
You can simply add following line of code in the Header section to enable auto refresh in an ASP.NET web page.
<meta http-equiv="refresh" content="120">


其中120是指刷新页面之前需要花费的秒数.
另外,如果您将URL放在标记内,也可以重定向到特定页面.


Where 120 refers to the number of seconds it will take before refreshing the page.
Also you can redirect to a specific page if you put the URL inside the tag.

<meta http-equiv="refresh" content="15;url=http://www.portinggurus.com">


实际上,这是标准的HTML功能,而没有特定于ASP.NET的功能.无论是ASP.NET页面还是HTML页面,还是用Java,PHP,ColdFusion,Perl等制成的页面,都可以看到自动刷新的相同效果.
如果要动态设置刷新时间,则可以在ASP.NET中通过在Page_Load函数中添加服务器端代码来设置刷新时间来进​​行设置,如下所示:


In reality, this is standard HTML functionality and nothing specific to ASP.NET. The same effect of auto-refresh would be seen whether it is an ASP.NET page or just a HTML page, or a page made in Java, PHP, ColdFusion, Perl or the like.
If you want to set the refresh time dynamically then that can be done in ASP.NET by adding server side code in the Page_Load function to set it, as shown below:

Response.AppendHeader("Refresh", "120")



在此处获得带有源代码的良好示例:
自动刷新网页 [



Get a good example with source code here:
Auto Refresh Web Page[^]


<html>
<head>
<script type="text/JavaScript">
<!--
function timedRefresh(timeoutPeriod) {
	setTimeout("location.reload(true);",timeoutPeriod);
}
//   -->
</script>
</head>
<body onload="JavaScript:timedRefresh(120000);">
<p>This page will refresh every 5 seconds. This is because we're using the 'onload' event to call our function. We are passing in the value '120000', which equals 5 seconds.</p>

</body>
</html>


将页面呈现给客户端后,您只有两种方式可以强制刷新.一种是Javascript
Once the page is rendered to the client you have only two ways of forcing a refresh. One is Javascript
setTimeout("location.reload(true);", timeout);


第二个是元标记:


The second is a Meta tag:

<meta http-equiv="refresh" content="600"></big>


您可以在服务器端设置刷新间隔.


You can set the refresh intervals on the server side.


这篇关于每两分钟自动刷新一次页面吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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