JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<button id="notify">Notify</button>
JavaScript
if ('Notification' in window) {
function notifyUser() {
var title = 'example title';
var options = {
body: 'example body',
icon: 'example icon'
};
if (Notification.permission === "granted") {
// If it's okay let's create a notification
var notification = new Notification(title, options);
} else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
// If the user accepts, let's create a notification
if (permission === "granted") {
var notification = new Notification(title, options);
}
});
}
}
$('#notify').click(function() {
notifyUser();
return false;
});
} else {
alert('not happening');
}