views:

32

answers:

1

So ideally here is what I am trying to accomplish (keep in mind I am a beginner, so bear with me):

Creating an app that at interval x (let's play with interval x = 15 minutes) a notification pops up prompting the user the take action. So every 15 minutes, take action (so you know, to alert them, this will be a browser flash and a title flicker / change). If the user takes action, reset the timer for another x amount (again, lets play with x = 15 minutes). If they don't take action, keep flashing browser window and changing title. Any suggestions on how to accomplish this? Thanks so much.

+1  A: 

You'll want to use setTimeout for this. There is another function, setInterval, but you don't want the event to occur while the user has not yet clicked on the notification (ie, after 15 minutes a notification pops up, but if the user has not dismissed the notification, you don't want the event to run again).

setTimer works in the following way:

setTimeout(code,millisec,lang)

code is a reference to the function or the code to be executed. millisec is the number of milliseconds to wait before executing the code lang is optional. It is the scripting language: JScript, VBScript, or JavaScript

for your purposes, you could use:

function setNextTimeout() {
    // 15 minutes * 60 seconds * 1000 milliseconds
    var t=setTimeout("displayAlert()", 15 * 60 * 1000)
}

function displayAlert() {
    alert('I am displayed after 15 minutes!');
    setNextTimeout();
}

setNextTimeout();
umop
How would I factor in a user event - lets, for this example, say on user mouse move - simply because whether they are on the current window and move, or switch from another, this will work - what would you suggest?
Brian
For that, you'll need to use an onmousemove event handler and reset the timer if you see it happening. Here's some information I googled: http://www.quirksmode.org/js/events_mouse.html
umop