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.
Adding data to a notification - JavaScript Tutorial
From the course: JavaScript: Progressive Web Applications
Adding data to a notification
- Let's see if we can show a more complex notification. To do that, let's compose an object literal inside the conditional statement that asks the user for permission to show notifications. Okay, so I'm gonna do that just before we call notify, because we're gonna want to pass this options object into our notify function. So let's create a var that holds our options, set it equal to, and we'll create an options literal. We're gonna include a body property, and that's an extra string to be displayed in a notification, so let's do body, and we'll set that to See What's New. Notice I had to escape out the apostrophe, because I'm using single quotes to encapsulate the string. Again, that beats trying to help me with punctuation and it actually hurts. The next property, let's do an icon property. That's gonna take a URL of an image to display with a notification. I'm gonna use the Android Chrome 192 by 192 file. So let's add an icon property, and that, as a string, is gonna be the path to…
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)
-
-