Skip to content

Instantly share code, notes, and snippets.

@Akhu
Created May 12, 2017 12:59
Show Gist options
  • Save Akhu/3feb0a2ecf70323a3de6adde88befe13 to your computer and use it in GitHub Desktop.
Save Akhu/3feb0a2ecf70323a3de6adde88befe13 to your computer and use it in GitHub Desktop.
A vanilla JS sample of browser notification
// request permission on page load
document.addEventListener('DOMContentLoaded', function () {
if (Notification.permission !== "granted")
Notification.requestPermission();
});
function notifyMe(notificationText,notificationTitle) {
if (!Notification) {
alert('Desktop notifications not available in your browser. Try Chromium.');
return;
}
if (Notification.permission !== "granted")
Notification.requestPermission();
else {
var notification = new Notification(notificationTitle, {
icon: '/images/chut-logo.png',
body: notificationText,
});
notification.onclick = function () {
window.open('http://localhost:3000/');
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment