Skip to content

Instantly share code, notes, and snippets.

@jetsanix
Created July 12, 2012 09:22
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jetsanix/3096976 to your computer and use it in GitHub Desktop.
Save jetsanix/3096976 to your computer and use it in GitHub Desktop.
OS X Notification Center in Safari 6 & Chrome 21+

OS X Notification Center in Safari 6 & Chrome 21+

OS X Mountain Lion adds Notification Center for managing alerts. Just like growl, but better.

Safari 6 and latest Chrome (21+) expose HTML5 notifications API to sites. Every site need to have permission for showing notifications.

Specification is very new and completely different from older version Chrome had. Developer doesn't have to watch for complicated NotificationCenter.

The syntax is very simple:

var notification = new Notification('Title', {body: 'text'});
notification.show();

// The event part is optional, you need to use it before .show().
notification.addEventListener('show', function() {
  setTimeout(function() {
    notification.cancel();
  }, 2000);
}, true);

Screenshots:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment