FireFox 插件/javascript setTimeout 问题

发布于 2024-11-08 23:42:09 字数 298 浏览 0 评论 0原文

当我的扩展启动时,它会在我的网站上查询 xml 文件,一旦获取该文件,它就会发出一个简单的警报,告诉用户最新的文件已下载。

问题是,由于该文件只有几 kb,它发生的速度非常快,并且警报会等待单击“确定”后才开始加载浏览器。

我通过将警报设置为 30 秒的 setTimeout 解决了这个问题,这应该让浏览器有足够的时间在警报出现之前加载(以及开始加载任何已保存的选项卡)。

我的问题很简单,保持计时器像这样运行......它会占用大量资源还是会影响较慢的机器或其他什么? 30 秒对于 Firefox 插件中的计时器来说太长了吗?

When my extension starts it queries my site for an xml file, once it gets the file it fires off a simple alert telling the user the latest file has been downloaded.

The problem is since the file is just a few kb it can happen very fast and the alert waits for "ok" to be clicked before it starts loading the browser.

I solved this by putting the alert in a setTimeout of 30 seconds, which should give the browser plenty of time to load (as well as start loading any saved tabs) before the alert comes up.

My question is a simple one, keeping the timer running like that... is it heavy on resources or will it affect slower machines or anything?
Is 30 seconds too long to have a timer in a Firefox addon?

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

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

发布评论

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

评论(3

半暖夏伤 2024-11-15 23:42:09

如果明智地使用,计时器不会占用大量资源(即,不要以 1 毫秒的间隔启动 3000 个计时器)。

虽然,人们对警报的使用感到好奇……这似乎从来都不是正确的做法。

Timers are not heavy on resources, if used judiciously (i.e., don't spin up 3000 timers at 1ms intervals).

Although, one wonders about the use of an alert... This doesn't seem like it is ever the right thing to do.

梦途 2024-11-15 23:42:09

关于计时器,您已经有了一些很好的答案,所以让我们重点关注警报对话框本身。您绝对不应该以这种方式使用警报对话框。用户不太喜欢它们。

相反,使用弹出式烤面包机警报告诉用户文件已下载。有关使用弹出警报服务的信息,请参阅此 MDC 文档:
https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIAlertsService

You already have some good answers regarding the timer, so let's focus on the alert dialog itself. You should never use an alert dialog in this way. Users don't like them very much.

Instead, use a popup toaster alert to tell the user the file has downloaded. See this MDC doc for information on using the popup alert service:
https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIAlertsService

情绪少女 2024-11-15 23:42:09

计时器在触发之前不会执行任何操作。它只是位于计时器队列中。如果周围没有其他计时器(不太可能),计时器线程甚至不会醒来,直到该计时器线程触发为止。

The timer does nothing until it comes time for it to fire. It just sits there in the timer queue. If there are no other timers around (unlikely) the timer thread won't even wake up until it's time for this one to fire.

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