Created
May 12, 2017 12:59
-
-
Save Akhu/3feb0a2ecf70323a3de6adde88befe13 to your computer and use it in GitHub Desktop.
A vanilla JS sample of browser notification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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