当前位置: 首页 > news >正文

electron dialog.showMessageBox使用案例

electron 版本:25.3.1

index.html

<!DOCTYPE html>
<html>
<head><meta charset="UTF-8"><title>Hello World!</title><meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';"/>
</head>
<body>
<h1>Hello World!</h1>
<button id="sad">点我弹出消息对话框</button>
<script>const {ipcRenderer} = require('electron')document.querySelector('#sad').addEventListener('click', () => {ipcRenderer.send('open-message-dialog')})
</script>
</body>
</html>

main.js

const {app, BrowserWindow, ipcMain, dialog} = require('electron')function createWindow() {let win = new BrowserWindow({width: 800,height: 600,webPreferences: {nodeIntegration: true,contextIsolation: false}})win.loadFile('index.html')ipcMain.on('open-message-dialog', () => {dialog.showMessageBox({title: '消息',message: '这是一个消息框。',type: 'info',buttons: ['确定', '取消']})})
}app.whenReady().then(createWindow)app.on('window-all-closed', function () {if (process.platform !== 'darwin') app.quit()
})app.on('activate', () => {if (BrowserWindow.getAllWindows().length === 0) {createWindow()}
})

效果展示
在这里插入图片描述

http://www.lryc.cn/news/99815.html

相关文章:

  • 代码随想录算法训练营第二十二天 | 读PDF复习环节2
  • TimescaleDB时序数据库初识
  • Numpy-聚合函数
  • 企业博客资讯如何高效运营起来?
  • 跟我学c++中级篇——模板的继承
  • 需求分析案例:消息配置中心
  • 自动化测试——环境
  • 短视频矩阵营销系统技术开发者开发笔记分享
  • vue2和vue3引用ueditor的区别
  • 【每日运维】RockyLinux8非容器化安装Mysql、Redis、RabitMQ单机环境
  • 第一次后端复习整理(JVM、Redis、反射)
  • python的web学习(一)-初识django
  • JavaWeb+jsp+Tomcat的叮当书城项目
  • 【嵌入式Linux系统开发】——系统移植概述
  • 升讯威在线客服系统是如何实现对 IE8 完全完美支持的(怎样从 WebSocket 降级到 Http)【干货】
  • 用VMware给运行在VMware上的CentOS7生成一个以SSH方式连接VMware上的CentOS7的运行在Windows上的命令行窗口
  • C语言基础-3
  • Python 编程规范进阶(1) | 命名规范
  • 算法----二叉搜索树中第K小的元素
  • 阿里Java开发手册~安全规约
  • 消息中间件RabbitMQ——学习笔记
  • 爬虫005_python类型转换_其他类型转换为整型_转换为Float类型_转换为字符串_转换为布尔值---python工作笔记023
  • SpringBoot复习:(5)使用PropertySource注解
  • webrtc 支持H265(三) 总结
  • Windows使用Notepad++编辑Linux服务器的文件
  • 升级你的数据采集引擎 使用多线程与代理池提升HTTP代理爬虫性能
  • flask实现一个登录界面
  • redis的四种模式优缺点
  • maven本地仓库地址修改+maven国内镜像设置+maven运行所需pos.xml文件配置基本写法
  • Jenkins集成SonarQube保姆级教程