I'm currently using the following code to show Desktop notifications in Google Chrome:
new Notification(data.sender.displayName, {
icon: '/images/logo.png',
body: data.content,
});
This is for a chat application and it doesn't make sense to show notifications on the same page as the chat. How can I make it so that the notification only appears when the tab is inactive or if the window is out of focus?
Thanks!
I'm currently using the following code to show Desktop notifications in Google Chrome:
new Notification(data.sender.displayName, {
icon: '/images/logo.png',
body: data.content,
});
This is for a chat application and it doesn't make sense to show notifications on the same page as the chat. How can I make it so that the notification only appears when the tab is inactive or if the window is out of focus?
Thanks!
Share Improve this question asked Jan 15, 2015 at 17:04 CarpetfizzCarpetfizz 9,20923 gold badges95 silver badges155 bronze badges 01 Answer
Reset to default 7Use the Visibility API to find out if the window is visible. You can use event listeners to set custom hide/unhide events. See here.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744359396a4570395.html
评论列表(0条)