我如何向他人发送网络/桌面通知?

时间:2015-09-02 15:00:58

标签: web notifications send subscribe

我希望在关闭我的网站后为我的网站访问者发送桌面通知

我如何让他们订阅? 以及如何为他们发送通知

这个网站制作相同的jeapie.com,但我想制作自己的

我看过一些代码,但它只向我发送通知

if (event.target.id === 'button-wn-show-preset') {
  // Uses the preset parameters
} else {
  // Uses the custom parameters
}

1 个答案:

答案 0 :(得分:0)

您似乎想要像JavaScript中的<!DOCTYPE html> <html> <body onbeforeunload="notifyMe()"> <script> // request permission on page load document.addEventListener('DOMContentLoaded', function () { if (Notification.permission !== "granted") Notification.requestPermission(); }); function notifyMe() { if (!Notification) { alert('Desktop notifications not available in your browser. Try Chromium.'); return; } if (Notification.permission !== "granted") Notification.requestPermission(); else { var notification = new Notification('Notification title', { icon: 'http://cdn.sstatic.net/stackexchange/img/logos/so/so-icon.png', body: "Hey there! You've been notified!", }); notification.onclick = function () { window.open("http://stackoverflow.com/a/13328397/1269037"); }; } } </script> </body> </html> 事件处理程序。当用户离开页面时,将出现JS弹出警告。查看W3 Reference了解用法。

上面的链接示例:

:symbol
相关问题