node.js - 桌面上的推送通知在关闭后不断弹出
问题描述
我正在使用 Node、Express 和 Socket.io 构建一个聊天应用程序
这是它的链接:https ://shahchat.herokuapp.com/
这是一个样本测试工作
出于某种原因,试图关闭弹出窗口是一次又一次地重新加载它。
任何帮助或建议将不胜感激
JS代码
function notifyMe(user, message) {
// Let's check if the browser supports notifications
if (!("Notification" in window)) {
alert("This browser does not support desktop notification");
}
// Let's check if the user is okay to get some notification
else if (Notification.permission === "granted") {
// If it's okay let's create a notification
var options = {
title: user,
body: message,
dir: "ltr"
};
var notification = new Notification(user, options);
}
套接字代码
socket.once("notify everyone", data => {
notifyMe(data.user, data.comment);
});
解决方案
您可以使用Chrome 通知,它适用于桌面和移动端。
推荐阅读
- reactjs - 返回上一个屏幕时执行 useQuery() 挂钩反应原生堆栈导航器
- javascript - 如何合并数组数组
- android - 在构建 VSCode 和 Android Studio (Flutter) 的 gradle 时,配置根项目“android”时出现问题
- java - 如何在 java 中创建或配置 Filehandler 以在不同的执行中对我的日志进行逻辑处理?
- r - 如何根据 R 中的最小日期差异为每个 ID 仅选择一行数据?
- powerbi - 根据同一表的另一列获取特定列的计数 - Power BI
- openvino - 问:如何获取 dldt buildinfo?
- django - 在 React 前端显示 rtsp 流
- excel - 宏按钮将文件移动到另一个文件夹
- node.js - 如何在构建模板时修复离子错误