web Notification api生成多个Notification,有办法获取所有

web Notification api生成多个Notification,有办法获取所有Notification对象吗?

var n = new Notification(o.user.userid);

                n.onshow = function () {
                    setTimeout(n.close.bind(n), 5000);
                }

new了n个,然后不想设置定时关闭,想一次性关闭所有Notification,有办法获取所有Notification对象吗?


慕桂英4014372
浏览 770回答 1
1回答

富国沪深

定义一个数组,每次生成的时候把Notification对象加进去不就行了,期待大家更好地解决办法if (window.Notification && Notification.permission !== "denied") {                     Notification.requestPermission(function (status) {                                             var n = new Notification(title, {                                                 body: content,                            icon: icon                         });                         NotificationItems.push(n);                     });                 }操作的时候while (NotificationItems.length > 0) {                NotificationItems[0].close();                 NotificationItems.shift();             }
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript