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 () { console.log('Show'); // Close the Notification after 1 second setTimeout(function() {notification.close();}, 1000); };
You can...