开发者

FireFox addon / javascript setTimeout question

开发者 https://www.devze.com 2023-03-07 16:12 出处:网络
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.

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 pr开发者_运维百科oblem 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?


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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消