我正在为我的项目使用通知 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/