function spawnNotification(theBody, theIcon, theTitle, theLink) {
var options = {
body: theBody,
icon: theIcon
}
var notification = new Notification(theTitle, options);
notification.onclick = function() {
var myWindow = window.open(theLink,"_blank");
myWindow.focus();
};
setTimeout(notification.close.bind(notification), 4000);
}
I am trying to open a new tab and to focus it , when the notification box is clicked.
I am using the above fuction to open a link in a new tab and to focus on that newly opened tab. But its not working.
New tab is opened, but the focus remains on the old tab itself. How can I solve this?
function spawnNotification(theBody, theIcon, theTitle, theLink) {
var options = {
body: theBody,
icon: theIcon
}
var notification = new Notification(theTitle, options);
notification.onclick = function(event) {
event.preventDefault(); // prevent the browser from focusing the Notification's tab
window.open(theLink, '_blank');
}
setTimeout(notification.close.bind(notification), 7000);
}
I changed my code as shown above. Now it works perfect. See: https://developer.mozilla.org/en-US/docs/Web/API/Notification/onclick#Examples
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With