Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/393.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 第次电子窗口模糊事件[未处理错误]_Javascript_Electron - Fatal编程技术网

Javascript 第次电子窗口模糊事件[未处理错误]

Javascript 第次电子窗口模糊事件[未处理错误],javascript,electron,Javascript,Electron,此错误在应用程序加载时很少发生(并非始终)。index.js是主文件,在package.json中选择,script.js是连接到electron应用程序主html文件的文件 index.js const {app, BrowserWindow} = require('electron'); const path = require('path'); const url = require('url'); let window; var APP_DIR = '/app/'; var IMG

此错误在应用程序加载时很少发生(并非始终)。index.js是主文件,在package.json中选择,script.js是连接到electron应用程序主html文件的文件

index.js

const {app, BrowserWindow} = require('electron');
const path = require('path');
const url = require('url');

let window;

var APP_DIR = '/app/';
var IMG_DIR = '/images/';

function createWindow() {
    window = new BrowserWindow({
        webPreferences: { nodeIntegration: true },
        width:610,
        height:679,
        icon: path.join(__dirname, APP_DIR, IMG_DIR, 'icon.png'),
        frame: false,
        resizable: false,
        fullscreenable: false
    });

    window.loadURL(url.format({
        pathname: path.join(__dirname, APP_DIR, 'index.html'),
        protocol: 'file:',
        slashes: true
    }));
}

app.on('ready', createWindow);
script.js(发生错误的地方)


如何修复它?

函数
BrowserWindow.getFocusedWidow()
在所有窗口模糊时返回
null
。您收到错误是因为无法在
null
上注册侦听器

请尝试以下方法:

const mainWindow=require('electron').remote.getCurrentWindow()
mainWindow.on('blur',function(){
windowBlurHandler()
})
var {BrowserWindow} = require('electron').remote;

BrowserWindow.getFocusedWindow().on('blur', function() {
    windowBlurHandler(); //a function
});