Created
July 13, 2015 16:50
-
-
Save autonome/abf43ffea35fce9bad56 to your computer and use it in GitHub Desktop.
mozAlarms example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Manifest snippets */ | |
"type": "privileged", | |
"permissions": { | |
"alarms": { | |
"description": "Required to schedule alarms" | |
} | |
}, | |
"messages": [ | |
{ "alarm": "/index.html" } | |
] | |
/* Code */ | |
function setUpAlarm() { | |
// This the date to schedule the alarm | |
var myDate = new Date(+new Date() + 60000); | |
console.log('date: ', myDate) | |
// This is arbitrary data pass to the alarm | |
var data = { | |
foo: "bar" | |
} | |
// The "honorTimezone" string is what make the alarm honoring it | |
var request = navigator.mozAlarms.add(myDate, "honorTimezone", data); | |
request.onsuccess = function () { | |
console.log("The alarm has been scheduled"); | |
}; | |
request.onerror = function () { | |
console.log("An error occurred: " + this.error.name); | |
}; | |
} | |
navigator.mozSetMessageHandler("alarm", function (alarm) { | |
console.log('alarm fired') | |
alert("alarm fired: " + JSON.stringify(alarm.data)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment