A Pen by Cat Burston on CodePen.
Created
August 4, 2014 12:59
-
-
Save catburston/b7c39762ee54bda23aa2 to your computer and use it in GitHub Desktop.
Notifications API
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
<button onclick="notifyMe()">click me</button> |
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
function notifyMe() { | |
if (window.Notification) { | |
console.log("Browser supports notifications"); | |
} | |
if (Notification.permission !== 'denied') { | |
Notification.requestPermission(function (permission) { | |
if (permission === 'granted') { | |
//var options = []; | |
var notification = new Notification("HIIIIII", { | |
icon: "http://www.lorempixel.com/90/90", | |
body: "Notification body goes here." | |
}); | |
} | |
notification.onshow = function () { | |
setTimeout(notification.close, 100); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment