HTML5 桌面通知(最好是 Angular)

HTML5 Desktop Notifications (ideally with Angular)

我希望能够向用户发送桌面通知(不在浏览器内 window)并且我知道我必须让用户选择在 chrome 中打开对话框问题.

我正在使用 MEAN 堆栈,并在前端使用 browserify/bowserify,我可以在客户端使用 bower 或 npm 包。我使用 CommonJS 模式,所以如果解决方案或示例采用该格式,或者更容易迁移到该格式,它会帮助我理解它。

解决这个问题的最佳方法是什么,是否有一个 Angular/React 插件(我必须承认我自己找不到)。

我真的只需要一次显示一个,我很乐意只显示最新的并自动删除那里的所有内容,理想情况下是跨浏览器解决方案(只有在需要时才可以是最新版本是)。

欢迎提出任何想法。

使用node notifier模块。当然只是服务器端。

var notifier = require('node-notifier');
notifier.notify({
    title: 'Title',
    message: 'Message'
}, function(err, resp) {
    if(err) {
        console.log(err);
    }
});

澄清一下,我指的是前端解决方案。但是我遇到了这个,我已经对其进行了编辑和改进。

为了清楚起见,这很简单 JavaScript,我将使用我自己的一些方法 link 将其 Angular。

document.addEventListener('DOMContentLoaded',function(){
document.getElementById('notifyButton').addEventListener('click',function(){

    if(! ('Notification' in window) ){
        console.log('Web Notification not supported');
        return;
    }   

    Notification.requestPermission(function(permission){
            var notification = new Notification("Title",{body:'HTML5 Web Notification API',icon:'http://i.stack.imgur.com/Jzjhz.png?s=48&g=1', dir:'auto'});
            setTimeout(function(){
                notification.close();
            },3000);
        });
    });
});

我想你可以使用这项 angular 服务。 https://github.com/sagiegurari/angular-web-notification