I have the following JS code used to send the desktop notification to the user, but it will only run when the page is open in the browser. Is it possible to show the desktop notification even when the page is not open, but has been previously opened (like Facebook is doing).
document.addEventListener('DOMContentLoaded', function () {
if (Notification.permission !== "granted")
Notification.requestPermission();
});
function displayDesktopNotification(note, datetime) {
if (!Notification) {
alert('Desktop notifications not available in your browser. Try Chromium.');
return;
}
if (Notification.permission !== "granted")
Notification.requestPermission();
else {
var notification = new Notification('', {
icon: '/Images/share.png',
body: note + ' ' + datetime,
});
notification.onclick = function () {
window.open("http://localhost/home?");
};
}
}
displayDesktopNotification("testing", "2017-07-06 09:56:00");