April 2010
Notificaciones de escritorio con WebKit | aNieto2K →
anieto2k.com
function Notifier() {}
// Devuelve "true" si el navegador dispone del soporte
Notifier.prototype.HasSupport = function() {
retun (window.webkitNotifications);
}
// Petición de permisos para enviar notificaciones desde esa URL.
Notifier.prototype.RequestPermission = function(cb) {
window.webkitNotifications.requestPermission(function() {
if (cb) { cb(window.webkitNotifications.checkPermission() == 0); }
});
}
// Mostramos la notificación indicando icono, título y cuerpo
Notifier.prototype.Notify = function(icon, title, body) {
if (window.webkitNotifications.checkPermission() == 0) {
var popup = window.webkitNotifications.createNotification(
icon, title, body);
popup.show();
return true;
}
return false;
}
Podemos ver un ejemplo funcionando (desde Chrome o versiones de Webkit más modernas) (código fuente).