notification.js 659 B

1234567891011121314151617181920212223
  1. function sendNotification() {
  2. new Notification("Notification title", {
  3. body: "This is the notification body",
  4. });
  5. }
  6. document.getElementById("notification").addEventListener("click", function () {
  7. if (Notification.permission === "default") {
  8. Notification.requestPermission()
  9. .then(function (response) {
  10. if (response === "granted") {
  11. sendNotification();
  12. } else {
  13. registerResponse("Permission is " + response);
  14. }
  15. })
  16. .catch(registerResponse);
  17. } else if (Notification.permission === "granted") {
  18. sendNotification();
  19. } else {
  20. registerResponse("Permission is denied");
  21. }
  22. });