Let's say I have a site and it sends a notification in the background while the tab is still open. How do I have the browser switch to my tab if the user clicks on my notification using JavaScript (pure, no jQuery)?
Let's say I have a site and it sends a notification in the background while the tab is still open. How do I have the browser switch to my tab if the user clicks on my notification using JavaScript (pure, no jQuery)?
Share asked Apr 5, 2018 at 19:44 herronjoherronjo 951 silver badge8 bronze badges1 Answer
Reset to default 10I'm assuming you are using the Notifications API. In your code, after you create the notification, you'll want to add an onclick
event and tell it to focus on the tab (rather than the browser).
let notification = new Notification('Test Notification'});
notification.onclick = function () {
window.parent.parent.focus();
};
According to the documentation, you can also use the addEventListener()
method instead of onclick
if you like.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744935863a4602019.html
评论列表(0条)