【问题标题】:Notification pop-up on desktop from web site从网站在桌面上弹出通知
【发布时间】:2018-07-14 01:02:10
【问题描述】:

我需要能够在桌面的右下角显示通知弹出窗口,而不是像 toastr 这样的浏览器窗口的右下角,需要是桌面的右下角。我想我看过它,但不记得在哪里。

有人有什么想法吗?

我猜是 javascript/jquery?

【问题讨论】:

  • Gmail 会做类似的事情,如果你指的是这个
  • 是的,但您不需要启用通知吗?我承认我还没有尝试过,但我正在寻找更多关于它是如何实现代码的,谢谢
  • 如果您正在寻找类似 Gmail 的弹出窗口,请edit 反映您的问题

标签: javascript jquery notifications


【解决方案1】:

如果用户授予网站使用权限,您正在寻找可以做到这一点的 notification()。

来自链接的文档:

<button onclick="notifyMe()">Notify me!</button>

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 whether notification permissions have already been granted
  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
  else if (Notification.permission !== "denied") {
    Notification.requestPermission(function (permission) {
      // If the user accepts, let's create a notification
      if (permission === "granted") {
        var notification = new Notification("Hi there!");
      }
    });
  }

  // At last, if the user has denied notifications, and you 
  // want to be respectful there is no need to bother them any more.
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-02
    • 1970-01-01
    相关资源
    最近更新 更多