Skip to content

Instantly share code, notes, and snippets.

@hardiksondagar
Last active March 7, 2018 12:27
Show Gist options
  • Save hardiksondagar/450d804a0b8e5a313d52 to your computer and use it in GitHub Desktop.
Save hardiksondagar/450d804a0b8e5a313d52 to your computer and use it in GitHub Desktop.
Chrome desktop Notification example
<button onclick="notifyMe()">Notify me!</button>
// Credit : http://stackoverflow.com/questions/2271156/chrome-desktop-notification-example
// request permission on page load
document.addEventListener('DOMContentLoaded', function () {
if (Notification.permission !== "granted")
Notification.requestPermission();
});
function notifyMe() {
if (!Notification) {
alert('Desktop notifications not available in your browser. Try Chromium.');
return;
}
if (Notification.permission !== "granted")
Notification.requestPermission();
else {
var notification = new Notification('Notification title', {
icon: 'http://cdn.sstatic.net/stackexchange/img/logos/so/so-icon.png',
body: "Hey there! You've been notified!",
});
notification.onclick = function () {
window.open("http://stackoverflow.com/a/13328397/1269037");
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment