javascript - Show Chrome desktop notifications only when tab is inactive - Stack Overflow

I'm currently using the following code to show Desktop notifications in Google Chrome:new Notifica

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 0
Add a ment  | 

1 Answer 1

Reset to default 7

Use 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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信