Javascript 第次电子窗口模糊事件[未处理错误]
此错误在应用程序加载时很少发生(并非始终)。index.js是主文件,在package.json中选择,script.js是连接到electron应用程序主html文件的文件 index.jsJavascript 第次电子窗口模糊事件[未处理错误],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
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
});