js发送通知
JS 发送 通知
2023-06-13 09:17:03 时间
文档:https://developer.mozilla.org/zh-CN/docs/Web/API/Notification
https://developer.mozilla.org/zh-CN/docs/Web/API/notification/requestPermission
代码如下
Notification.requestPermission().then((permission) => {
// If the user accepts, let's create a notification
if (permission === "granted") {
const notification = new Notification("Hi there!");
// …
}
});
效果:
完整代码:
function notifyMe() {
if (!("Notification" in window)) {
// Check if the browser supports notifications
alert("This browser does not support desktop notification");
} else if (Notification.permission === "granted") {
// Check whether notification permissions have already been granted;
// if so, create a notification
const notification = new Notification("Hi there!");
// …
} else if (Notification.permission !== "denied") {
// We need to ask the user for permission
Notification.requestPermission().then((permission) => {
// If the user accepts, let's create a notification
if (permission === "granted") {
const notification = new Notification("Hi there!");
// …
}
});
}
// At last, if the user has denied notifications, and you
// want to be respectful there is no need to bother them anymore.
}
相关文章
- js JavaScript vue 时间戳 转换 日期 YYYY-MM-DD hh:mm:ss 简洁写法
- linux如何安装nodejs_js 循环里面结束整个方法
- html如何只刷新页面指定,js控制页面刷新 JS刷新当前页面的几种方法总结
- JS跳转代码_js中跳转页面路径
- js的基础知识
- 【说站】js中for-of语句如何理解
- Js排序算法_js 排序算法
- 原生js发送post请求_javascript发送post请求
- 在考虑闭包的情况下JS变量存储在栈与堆的区分
- JS面试题-js新增基本数据类型BigInt
- JS设置定时器_js设置定时器
- leetcode 11. 盛最多水的容器 js实现
- js将整数转换成IP地址的教程
- Node.js前端如何使用反向代理解决跨域
- Ratchet:使用 HTML,JS,CSS 创建 iPhone App 原型
- JS简单的弹出层效果详解编程语言
- 创建JS文件:在Linux下实现自动化任务(linux创建js文件)
- Linux上的JS压缩工具(js压缩工具linux)
- 使用JS在网页中连接Oracle数据库(js网页链接oracle)
- 从前端JS里请求Redis资源,搭建高性能应用(前端js请求redis)
- 使用Oracle和JS开发新一代应用仿真世界(oracle js)
- js验证表单第二部分
- js宝典学习笔记(上)
- 用js实现上传图片前的预览(TX的面试题)
- js文本中搜索关键词输入效果
- js对象之JS入门之Array对象操作小结
- jQuery控制图片的hover效果(smartRollover.js)
- js图片自动切换效果处理代码
- 纯js简单日历实现代码
- js实现图片旋转的三种方法
- 项目中常用的JS方法整理
- 输入框过滤非数字的js代码