Skip to content

Instantly share code, notes, and snippets.

@ottino
Created July 4, 2020 00:57
Show Gist options
  • Save ottino/963dba7ba53e4b9a599f6e53e9006cec to your computer and use it in GitHub Desktop.
Save ottino/963dba7ba53e4b9a599f6e53e9006cec to your computer and use it in GitHub Desktop.
sw: Ejemplo para solicitud de envio de notificaciones
function notificarme() {
if ( !window.Notification ) {
console.log('Este navegador no soporta notificaciones!');
return;
}
// Si se le pregunto con anterioridad si
// desea recibir notificaciones
if ( Notification.permission === 'granted' ) {
new Notification('Hola!! - granted');
} // No se a negado
else if ( Notification.permission !== 'denied' ||
Notification.permission === 'default' ) {
// Realizar la solicitud al usuario
Notification.requestPermission( function ( permission ) {
console.log( permission );
if ( permission === 'granted' ){
new Notification('Hola!! - desde la pregunta!');
}
});
}
}
notificarme();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment