From the course: JavaScript: Progressive Web Applications
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Closing a notification - JavaScript Tutorial
From the course: JavaScript: Progressive Web Applications
Closing a notification
- Although I glossed over it, it's important to know that the notification is shown from the service worker, not the web app. The service worker runs on it's own thread, independent of the app. That's what allows it to display even when the app isn't active. So it makes sense to handle notification events in the service worker. Let's do the close event first. First, let's add a function that will allow us to track the users interaction with the notification. We'll do that inside SW.JS. So I'll scroll to the bottom and here's my function. I'm gonna call it close notification. And to that, I'm gonna pass a message to display and I'll get an event object from the event listener. And I just wanna write console.log, and we'll pass in whatever's in the message as well as any data stored in the event. So that event.notication.data. And then finally once I've written my message in the data to the console, we need to eventually close the notification. So the notification object stored inside…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
(Locked)
Introduction to notifications2m 21s
-
(Locked)
Requesting permission to show notifications5m 26s
-
(Locked)
Displaying a notification4m 50s
-
(Locked)
Adding data to a notification4m 36s
-
(Locked)
Closing a notification3m 33s
-
(Locked)
Handling the notification click event11m 25s
-
(Locked)
Push messaging overview1m 24s
-
(Locked)
Adding Firebase Cloud Messaging to the project2m 15s
-
(Locked)
Subscribing to push messaging6m
-
(Locked)
Handling push notifications3m 14s
-
(Locked)
Sending a tickle using cURL4m 57s
-
(Locked)
Sending data in a push message2m 9s
-
(Locked)
Installing Mozilla's Web Push library2m 51s
-
(Locked)
Modifying the push event handler2m 52s
-
(Locked)
Modifying the notification click event3m 48s
-
(Locked)
Creating the web push script6m
-
(Locked)
Testing the hosted app5m 7s
-
(Locked)
-
-