Skip to content

Instantly share code, notes, and snippets.

@Maras0830
Created April 6, 2017 03:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Maras0830/b7120d1a8ff1c304ec69b361357abd6e to your computer and use it in GitHub Desktop.
Save Maras0830/b7120d1a8ff1c304ec69b361357abd6e to your computer and use it in GitHub Desktop.
web notification
var socket_lottery_io = io.connect(location.origin + ':3033');
socket_lottery_io.on('lotteryNotification', function(data) {
setLotteryNotification(data);
});
function setLotteryNotification(data) {
Notification.requestPermission(function(status) {
if (status === 'granted') {
var notification = new Notification(data.lottery.title);
notification.onshow = function() {
setTimeout(function() {
notification.close();
}, 3000);
}
notification.onclick = function(event) {
event.preventDefault();
window.open(data.url, '_blank');
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment