【问题标题】:HTML5 Desktop Notifications (ideally with Angular)HTML5 桌面通知(最好使用 Angular)
【发布时间】:2015-07-19 07:58:43
【问题描述】:

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

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

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

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

欢迎任何想法。

【问题讨论】:

    标签: javascript angularjs html reactjs notifications


    【解决方案1】:

    我认为您可以使用此角度服务。 https://github.com/sagiegurari/angular-web-notification

    【讨论】:

    • 这并没有提供问题的答案。要批评或要求作者澄清,请在其帖子下方发表评论。
    【解决方案2】:

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

    为了清楚起见,这是纯 JavaScript,我将使用我自己的一些方法将其链接到 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);
            });
        });
    });
    

    【讨论】:

      【解决方案3】:

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

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

      【讨论】:

        猜你喜欢
        • 2013-11-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-09-03
        • 2015-06-30
        • 2011-06-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多