Book Image

NW.js Essentials

By : Alessandro Benoit, Roger Weng
Book Image

NW.js Essentials

By: Alessandro Benoit, Roger Weng

Overview of this book

Table of Contents (17 chapters)
NW.js Essentials
About the Author
About the Reviewers

The Web Notifications API

Notifications are small popups that are usually shown in the top-right corner of the screen that the operating system implements in order to share important events with the user. Each notification features a title, some descriptive text, and, optionally, a small thumbnail/icon; more notifications can be stacked.

I was really tempted to insert this argument in the Native UI APIs chapter as it shares the same goals, but Notifications APIs, although relatively young, are actually part of HTML5 specifications.

The code to implement web notifications inside your NW.js application is pretty straightforward:

var notification = new Notification('Notification Title', {
  icon: "icon32.png",
  body: "Here is the notification text"
notification.onclick = function () {
  console.log("Notification clicked");
notification.onshow = function () {
  // Close the Notification after 1 second
  setTimeout(function() {notification.close();}, 1000);

You can...