使用元刷新更新页面的替代方法

发布于 2024-10-03 19:58:04 字数 323 浏览 0 评论 0原文

过去,当我报道事件时,我使用带有 5 分钟计时器的元刷新来刷新页面,以便人们获得最新更新。

意识到这可能不是完美的方法(在 IE 中并不总是有效,会中断一个人的流程,为使用屏幕阅读器的人重新启动事物等)我想知道是否还有其他方法可以处理这个问题情况。

如果服务器上的 html 文件较新,是否可以让像 ajax 这样的东西每隔几分钟检查一次,并让它打印一条消息说“更新信息可用,单击此处刷新”?

如果这太疯狂了,那么用 javascript 来从 5 分钟开始倒计时并建议刷新怎么样?

如果有人可以向我指出教程或代码片段,我将不胜感激。我只是在电视上扮演程序员。 :-)

In the past, when I've covered events, I've used a meta-refresh with a 5 minute timer to refresh the page so people have the latest updates.

Realizing that this may not be the perfect way to do it (doesn't always work in IE, interrupts a person's flow, restarts things for people with screen readers, etc.) I'm wondering if there's any other way to do handle this situation.

Is it possible to have something like ajax check every few minutes if the html file on the server is newer and have it print a message saying "Update info available, click here to refresh"?

If that's crazy, how about a javascript that just counts down from 5 minutes and just suggests a refresh.

If anyone could point me to tutorials or code snippets I'd appreciate. I just play a programmer on TV. :-)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

妞丶爷亲个 2024-10-10 19:58:04

实际上,您关于定时 Ajax 测试的想法是一个好主意。我不确定这正是 StackOverflow 使用的,但它会定期检查是否已发布其他答案,并每隔一段时间向用户显示是否有更新。

我认为这是理想的,原因如下:

  • 它不引人注目 - 读者如果不关心,可以轻松忽略更新
  • 它不会浪费带宽 - 除非用户选择,否则不会重新加载
  • 它信息丰富 - 用户知道有更新并且可以选择采取行动。

我的看法是 - 让 ajax 脚本将最新的帖子 ID 发送到检查新脚本的脚本。该脚本可以查询您的数据库以查看是否有任何新帖子以及有多少。它可以返回这个数字。如果有新帖子,请显示一些(非模态)消息,包括更新数量,并让用户决定如何处理。

Actually, your thought on a timed Ajax test is an excellent idea. I'm not sure that is exactly what StackOverflow uses, but it checks periodically to see if other answers have been posted and shows the user, on an interval, if there are updates.

I think this is ideal for these reasons:

  • It's unobtrusive - the reader can easily ignore the update if they don't care
  • It won't waste bandwith - no reloading unless the user chooses to
  • It's informative - the user knows there's an update and can choose to act on it.

My take on how - have the ajax script send off the latest post id to a script that checks for new scripts. This script can query your database to see if there are any new posts, and how many there are. It can return this number. If there are new posts, show some (non modal) message including the number of updates, and let the user decide what to do about it.

明媚如初 2024-10-10 19:58:04
setInterval(function() {
  if (confirm("Its Been 5 Minutes. Would you like to refresh")) {
    window.location.reload(true);
    //Or instead of refreshing the page you could make an ajax call and determing if a newer page exists.  IF one does then reload.

  }
}, 300000);
setInterval(function() {
  if (confirm("Its Been 5 Minutes. Would you like to refresh")) {
    window.location.reload(true);
    //Or instead of refreshing the page you could make an ajax call and determing if a newer page exists.  IF one does then reload.

  }
}, 300000);
话少情深 2024-10-10 19:58:04

您可以在 JavaScript 中使用 setInterval 函数。

这是一个示例,

setInterval("refresh function", milliseconds, lang);

您将使用它将名称传递给实际刷新第一个参数页面的函数以及第二个参数刷新之间的毫秒数(5 分钟为 300000)。第三个参数lang是可选的

You can use the setInterval function in javascript.

here's a sample

setInterval("refresh function", milliseconds, lang);

You will use it passing a name to a function that actually refresh the page for the first param and the number of milliseconds between refresh for the second param (300000 for 5 minutes). The third parameter lang is optional

ㄟ。诗瑗 2024-10-10 19:58:04

如果用户要与乐谱进行交互并单击某些内容,那么刷新乐谱上的页面会有点粗鲁。我认为做一些诸如页面已更新通知之类的事情是理想的。

我将使用 jQuery 并对服务器上的文件执行 ajax 调用或返回更新后的数据。如果它比抛出 Growl 消息更新

Gritter - jQuery Growl System
Growl 使用 Gritter 的演示

Growl 消息可能会出现任何更改、新分数然后该消息中的一个选项用于刷新和查看新结果。

jQuery Ajax 信息

If the user would be interacting with the scores and clicking on things it would be a little rude to just refresh the page on them. I think doing something like a notification that the page has been updated would be ideal.

I would use jQuery and do an ajax call to the file on the server or something that will return the updated data. If it's newer than throw up a Growl message

Gritter - jQuery Growl System
Demo of what a Growl is using Gritter

A Growl message would come up possibly with whatever was changed, new scores and then an option within that message to refresh and view the new results.

jQuery Ajax information

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文