为了账号安全,请及时绑定邮箱和手机立即绑定

Chrome桌面通知示例

Chrome桌面通知示例

饮歌长啸 2019-07-05 16:38:09
Chrome桌面通知示例如何使用Chrome桌面通知?我想把它用在我自己的代码里。更新:这是博客文章用一个例子解释Webkit通知。
查看完整描述

3 回答

?
烙印99

TA贡献1829条经验 获得超13个赞

检查设计API规范(它仍然是一个草案)或检查源(页面不再可用)的一个简单的例子:它主要是一个调用window.webkitNotifications.createNotification.

如果您想要一个更健壮的示例(您正在尝试创建自己的GoogleChrome扩展,并且想知道如何处理权限、本地存储等),请查看Gmail通知扩展下载CRX文件而不是安装它,解压缩它并读取它的源代码。


查看完整回答
反对 回复 2019-07-05
?
青春有我

TA贡献1784条经验 获得超8个赞

看来window.webkitNotifications已经被废弃和移除了。然而,有一个新API,它似乎也适用于最新版本的Firefox。

function notifyMe() {
  // Let's check if the browser supports notifications
  if (!("Notification" in window)) {
    alert("This browser does not support desktop notification");
  }

  // Let's check if the user is okay to get some notification
  else if (Notification.permission === "granted") {
    // If it's okay let's create a notification
    var notification = new Notification("Hi there!");
  }

  // Otherwise, we need to ask the user for permission
  // Note, Chrome does not implement the permission static property
  // So we have to check for NOT 'denied' instead of 'default'
  else if (Notification.permission !== 'denied') {
    Notification.requestPermission(function (permission) {

      // Whatever the user answers, we make sure we store the information
      if(!('permission' in Notification)) {
        Notification.permission = permission;
      }

      // If the user is okay, let's create a notification
      if (permission === "granted") {
        var notification = new Notification("Hi there!");
      }
    });
  } else {
    alert(`Permission is ${Notification.permission}`);
  }}

密码


查看完整回答
反对 回复 2019-07-05
  • 3 回答
  • 0 关注
  • 1061 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号