zoukankan      html  css  js  c++  java
  • electron app弹出默认对话框后页面失去焦点问题

           最近再做electron app程序的做删除数据操作的时候遇到一个诡异的bug,页面点击删除按钮后,弹出确认对话框后,页面失去焦点,文本框无法点击输入任何参数,但是使用浏览器操作正常,最后确定是electron的bug,electron在弹出window默认对话框时会失去焦点,在githup上找到的解决方案是自己实现对话框覆盖window自带对话框,我的做法是覆盖window自带的alert和confirm方法,不多说了,现在贴代码。

    var userAgent = navigator.userAgent.toLowerCase();
    if (userAgent.indexOf(' electron/') > -1){
                const { dialog } = require('electron').remote;//修改默认对话框,修复electron弹出默认对话框后页面失去焦点的bug
                alert = function(str){
                      var options = {
                        type: 'warning',
                        buttons: ["确定"],
                        defaultId: 0,
                        cancelId:0,
                        detail:str,
                        message: ''
                      }
                      dialog.showMessageBoxSync(null,options)
                }
                confirm = function(str){
                      var options = {
                        type: 'warning',
                        buttons: ["确认","取消"],
                        defaultId: 0,
                        cancelId:1,
                        detail:'',
                        message: str
                      }
                      var flag = dialog.showMessageBoxSync(null,options);
                      if(flag==0){
                          return true;
                      }else{
                          return false;
                      }
               }
    }

    参考资料:https://github.com/electron/electron/issues/20400

  • 相关阅读:
    过滤器
    JSTL自定义标签
    EL表达式自定义函数
    和 区别
    JSTL标签
    jsp内置对象
    Java堆、栈和常量池以及相关String的详细讲解(转)
    jsp和servlet学习总结
    JAVA多线程实现的两种方式
    redis示例
  • 原文地址:https://www.cnblogs.com/yinliang/p/12175076.html
Copyright © 2011-2022 走看看