I want to alert users of my website for new content from the forums, private messages, etc on my website using the chromium desktop notifications but I am not sure how to do it the right way. Is there like a library or jquery plugin that I can use because I was thinking about using ajax that refreshes a php script every 30 or something seconds. Also, another thing - can I send notifications to users that don't have my website opened or do I have to have a browser extension for this part?
So far I have found this script on another thread for sending notifications and asking for permission.
<script type="text/javascript">
// request permission on page load
document.addEventListener('DOMContentLoaded', function () {
if (!Notification) {
alert('Desktop notifications not available in your browser. Try Chromium.');
return;
}
if (Notification.permission !== "granted")
Notification.requestPermission();
});
function notifyMe() {
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");
};
}
}
</script>
<button onclick="notifyMe()">Notify me!</button>