首页 > 其他分享 >12、electron showMessageBox消息对话框

12、electron showMessageBox消息对话框

时间:2022-12-13 10:45:24浏览次数:82  
标签:box 12 String 对话框 button buttons electron message

一、知识点

dialog.showMessageBox([browserWindow, ]options[, callback])

  • browserWindow BrowserWindow (可选)
  • options Object
    • type String - 可以是 "none""info""error""question" 或 "warning". 在 Windows, "question" 与 "info" 展示图标相同, 除非你使用 "icon" 参数.
    • buttons Array - buttons 内容,数组.
    • defaultId Integer - 在message box 对话框打开的时候,设置默认button选中,值为在 buttons 数组中的button索引.
    • title String - message box 的标题,一些平台不显示.
    • message String - message box 内容.
    • detail String - 额外信息.
    • icon NativeImage
    • cancelId Integer - 当用户关闭对话框的时候,不是通过点击对话框的button,就返回值.默认值为对应 "cancel" 或 "no" 标签button 的索引值, 或者如果没有这种button,就返回0. 在 OS X 和 Windows 上, "Cancel" button 的索引值将一直是 cancelId, 不管之前是不是特别指出的.
    • noLink Boolean - 在 Windows ,Electron 将尝试识别哪个button 是普通 button (如 "Cancel" 或 "Yes"), 然后再对话框中以链接命令(command links)方式展现其它的 button . 这能让对话框展示得很炫酷.如果你不喜欢这种效果,你可以设置 noLink 为 true.
  • callback Function

展示 message box, 它会阻塞进程,直到 message box 关闭为止.返回点击按钮的索引值.

如果 callback 被调用, 将异步调用 API ,并且结果将用过 callback(response) 展示.

 

二、示例:

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="button" id="btn" value="弹出消息对话框" />

    <script>
        const remote = require('@electron/remote');
        const dialog = remote.dialog;
        const fs =require('fs');

        let btn = document.getElementById('btn');
        btn.onclick = (e)=>{
            dialog.showMessageBox({
                type:'warning',
                title:'消息提醒',
                message:"是否取消打印?",
                buttons:['是','否','在想想'],
                detail:'仔细想想在做决定哦!',
            }).then(result=>{
                console.log(result);
                let response = result.response;
                console.log(response);
            }).catch(err=>{
                console.log(err);
            })
        }
    </script>
</body>
</html>

三、运行效果:

 

标签:box,12,String,对话框,button,buttons,electron,message
From: https://www.cnblogs.com/handsomeziff/p/16977895.html

相关文章

  • 【2022-12-09】连岳摘抄
    23:59遇到有承认自己错误的机会,我是最为愿意抓住的,我认为这样一种回到真理和理性的精神,比具有最正确无误的判断还要光荣。              ......
  • 2022-12-13 js判断对象是否为空
    第一种:json.stringifyvara={};console.log(JSON.stringify(a)=='{}');第二种:es6的Object.keysvara={};varb=Object.keys(b);console.log(b.length)......
  • 11、electron showSaveDialog保存文件
    一、知识点dialog.showSaveDialog([browserWindow,]options[,callback])browserWindow BrowserWindow(可选)options Objecttitle StringdefaultPath String......
  • Python3,3行代码,我把120M图片压缩到40M,从此再也不怕图片上传限制了。
    图片压缩方式​​1、引言​​​​2、PIL模块​​​​2.1quality方式​​​​2.1.1普通图片压缩​​​​2.1.2超大图片压缩​​​​2.2thumbnail方式​​​​3、OpenCV......
  • C++ Banking System[2022-12-13]
    C++BankingSystem[2022-12-13]DescriptionCustomeraccountInabank,therearemanytypesofaccounts.Tomakeitsimpleforthiscourseproject,weonlyco......
  • 2022.12.11-2022.12.12 总结
    2022.12.11-2022.12.12总结1.《代码随想录》二刷组合:https://leetcode.cn/problems/combinations/submissions/组合总和III:https://leetcode.cn/problems/combina......
  • C++编程题[2022-12-13]
    C++编程题[2022-12-13]题1:采用面向对象的程序设计方法编写一个一卡通管理系统,要求使用多继承、虚函数、虚基类,要有设定类别、计算消费额等功能。题2:定义一个处理时间......
  • 目前(12月13日)我的网站长这样~
    直接上源码:index.html<html> <head> <metacharset="utf-8"> <title>首页-HT</title> <script> window.oncontextmenu=function(e){ e.preventDefault......
  • day3-2022.12.12-flex布局初识
    一、完成以下布局。二、代码如下:<template><div><divclass="title">MYFirstFlexLearn</div><divclass="box"><divclass="item">......
  • Selenium12--元素基本操作
    文本框和文本域点击:click()清空:clear()输入:send_keys("数据")保留原内容,追加输入文本域输入换行时使用转义字符\n来表示获得属性值get_attribut......