Last Updated: February 25, 2016
·
752
· flurin

Notify your users with Web Notifications

Wouldn't it be swell if you could notify a user with an important message even if the browser isn't currently in use? Drumroll please: enter the Web Notifications API!

Check out these examples

How does it work?

To send notifications from a page you have to call requestPermission() first. This will make the browser bar pop up. After you've requested permission you can check if you have been granted permissions to send notifications by calling checkPermission().

After the initial bootstrapping, you can create a notification with createNotification(icon, title, content). You can even attach callbacks, for instance when the notification is shown or when it's dismissed by the user. To show the notification, you call show() on the created notification object.

Great, but can I use it today?

These examples currently work in Chrome and should work in Safari on Mountain Lion, but Mozilla is working on notifications too. The spec is still being drafted and is subject to change. The only version that's currently usable is actually based on an outdated spec.

More resources