Javascript 从网站在桌面上弹出通知

Javascript 从网站在桌面上弹出通知,javascript,jquery,notifications,Javascript,Jquery,Notifications,我需要能够在桌面的右下角显示通知弹出窗口,而不是像toastr这样的浏览器窗口的右下角,需要在桌面的右下角。我想我已经看过了,但不记得在哪里 有人有什么想法吗 我猜是javascript/jquery 您正在寻找通知(),如果用户授予网站使用权限,该通知可以执行此操作 来自链接文档: <button onclick="notifyMe()">Notify me!</button> function notifyMe() { // Let's check if

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

有人有什么想法吗


我猜是javascript/jquery

您正在寻找通知(),如果用户授予网站使用权限,该通知可以执行此操作

来自链接文档:

<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.
}
通知我!
函数notifyMe(){
//让我们检查一下浏览器是否支持通知
如果(!(“窗口中的通知”){
警报(“此浏览器不支持桌面通知”);
}
//让我们检查是否已授予通知权限
else if(Notification.permission==“已授予”){
//如果可以的话,让我们创建一个通知
var通知=新通知(“你好!”);
}
//否则,我们需要请求用户的许可
else if(Notification.permission!=“拒绝”){
Notification.requestPermission(函数(权限){
//如果用户接受,让我们创建一个通知
如果(权限==“已授予”){
var通知=新通知(“你好!”);
}
});
}
//最后,如果用户拒绝了通知,您
//想要尊重别人,就没有必要再打扰他们了。
}

Gmail就是这样做的,如果这就是你所指的是,但你不需要启用通知吗?我承认我没有尝试过,但我正在寻找更多关于如何实现代码智能化的方法。谢谢。如果你正在寻找类似Gmail的弹出窗口,请你的问题反映出来