Skip to content

Instantly share code, notes, and snippets.

@devpato
Created December 1, 2020 14:39
Show Gist options
  • Save devpato/479a2d11887424dea048ac25e26a9370 to your computer and use it in GitHub Desktop.
Save devpato/479a2d11887424dea048ac25e26a9370 to your computer and use it in GitHub Desktop.
Notification API
<button onclick="notifyMe()">Notify me!</button>
<script>
function notifyMe() {
//TO TEST THIS CODE CLICK ON THE UPPER RIGHT CORNER WHERE IT SAYS "OPEN IN NEW WINDOW"
if (!("Notification" in window)) {
alert("This browser does not support desktop notification");
} else if (Notification.permission === "granted") {
const notification = new Notification("Hi This Dot Labs!");
}
else if (Notification.permission !== "denied") {
Notification.requestPermission().then(function(permission) {
if (permission === "granted") {
const notification = new Notification("Hi This Dot Labs!");
}
});
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment