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.
<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 ); | |
} | |
}); | |
} |
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.