I am implementing the Web desktop notification for the users when a new message comes using JavaScript Notification interface of the Notifications API. This is working fine .But I need to stop desktop notification alert when the use is in the current tab. Please help me how to stop.I want notifications to be shown only when the user is not in the current tab
Below is my code I am using which is showing Desktop notification whenever a new message comes
if (Notification.permission !== "granted") {
Notification.requestPermission();
}
else {
var notification = new Notification('You have a new message",
{
icon: '/afi-favicon.ico',
body: message.Message,
});
notification.onclick = function () {
window.focus();
};