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.

Modifying the notification click event

Modifying the notification click event - JavaScript Tutorial

From the course: JavaScript: Progressive Web Applications

Start my 1-month free trial

Modifying the notification click event

- [Instructor] At this point, our notificationClick event will navigate to the loc property of the payload supply, but only if the app is open and visible. This means that the user must be currently looking at the app for the navigation to work. Since we can't rely on the app being in focus, and the intent of push messaging is to re-engage the user, we need to implement behavior that will wake the app if it's not currently active. To do this, we need to modify the notificationClick event handler. So let's scroll up and find the notificationClick event handler, and here's what we'll do. Just after we get the collection of all clients, I'm going to add a variable. So find where we've logged all the clients to the console, and hit ENTER. Let's create a variable called matchingClient. And I'm going to initialize that to be null. Then, as we loop through all of the clients available, if we find one that's visible, we'll assign that client to the matching client. So, just before the…

Contents