【笔记】JS向操作系统发送通知
前言
JS向操作系统发送通知
请求允许通知
- 通过浏览器请求授权允许发送系统通知
permission
:请求后的结果
default
:用户没有操作granted
:用户允许访问系统通知denied
:用户禁止访问系统通知
1 | const permission = await Notification.requestPermission(); |
发送通知
- 创建通知对象并立即发送通知
1 | const notification = new Notification("通知消息标题"); |
发送通知时携带消息其他信息
body
:消息通知正文icon
:消息通知的图标data
:消息通知对象存储的数据,可以存储任意数据类型的数据
1 | const notification = new Notification("通知消息标题", { |
定义通知是否保持常驻
requireInteraction
:通知是否保持常驻
false
:缺省值,4秒自动消失true
:通知保持常驻,除非手动关闭
1 | const notification = new Notification("通知消息标题", { |
定义通知标签
tag
:定义通知的标签,标签值相同的通知不会反复出现
1 | const notification = new Notification("通知消息标题", { |
没有定义通知标签
定义了通知标签