how to code a proper jquery timer to my liking
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 an开发者_如何学编程d changing title. Any suggestions on how to accomplish this? Thanks so much.
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();
精彩评论