Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save michaelschofield/7f69851ae11fc5e46421 to your computer and use it in GitHub Desktop.
Save michaelschofield/7f69851ae11fc5e46421 to your computer and use it in GitHub Desktop.
Simple Web Notification API Demo
<h1>Simple Web Notification</h1>
<button onclick="sendNotification()">Notify</button>
sendNotification = function() {
Notification.requestPermission( function( permission ) {
// Notification granted
if ( permission === 'granted' ) {
var options = {
body : 'Just kidding, there\'s nothing to be scared of.',
// icon : 'Put a url here to an image',
// onclick : trigger something if user clicks on notification,
// onerror : If something goes wrong with the notification
// silent : Can silence browser-default notification noises like DING or BLOOP or BUZZ,
title : 'Danger, Will Robinson!'
}
var notification = new Notification( 'Well, hello!', options );
}
});
}

Simple Web Notification API Demo

You would think this would be a little harder, but the API is really easy and convenient to use.

A Pen by Michael Schofield on CodePen.

License.

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