javascript - 按标签名称隐藏 JS 通知对象

标签 javascript notifications web-notifications

我正在为我的项目使用通知 API 来显示浏览器通知,其中每个通知都有一个唯一的标签 (ID),但我似乎无法找到一种方法来通过标签名称关闭或隐藏通知,而无需对对象调用 close 函数,因为它可能会被其原始页面之外的其他页面关闭。这种事情可能吗?

最佳答案

您可以将通知保存在 localStorage 中,然后检索并关闭。

例如

// on create
var n = new Notification('Notification Title', {
        tag: _this.attr('data-notification-id')
    });
window.localStorage.setItem('data-notification-id', n);

// then later
var n = window.localStorage.getItem('data-notification-id');
n.close();

关于javascript - 按标签名称隐藏 JS 通知对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30855832/

相关文章:

javascript - 如何从矩阵中提取子矩阵?

Android - 如何在很长一段时间后(一个月或更长时间)发出警报

javascript - 如何使 $(this) 选择器聚焦于当前元素?

javascript - 如何在GridView上调用applyFilter函数

java - 在 Java/Swing 中,有没有办法合法地使用 "attempt to mutate in notification"?

javascript - 在浏览器环境中拦截 HTML5 Web 通知

javascript - 防止多个网络通知?

html - 使用 HTML5 通知激活浏览器选项卡

javascript - 链式方法调用不适用于原始元素或克隆元素?

android - NotificationManager getActiveNotifications() 适用于旧设备