我正在尝试点击应用窗口全屏,但会收到以下错误main.js:29 Uncaught TypeError: Cannot read property 'setFullScreen' of undefined
main.js
const electron = require('electron')
// Module to control application life.
const app = electron.app
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow
function createWindow () {
// Create the browser window.
mainWindow = new BrowserWindow({width: 1200, height: 600})
// and load the index.html of the app.
mainWindow.loadURL(`file://${__dirname}/index.html`)
// Open the DevTools.
mainWindow.webContents.openDevTools()
// Emitted when the window is closed.
mainWindow.on('closed', function () {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null
})
}
function toggleFullScreen() {
mainWindow.setFullScreen(true)
}
答案 0 :(得分:9)
您可以在创建Windows对象时设置全屏。
const {BrowserWindow} = require('electron');
let win = new BrowserWindow({width: 800, height: 600, fullscreen: true});
在此处查看您在创建窗口时可以添加的选项Electron BrowserWindow
我的不好,我忘了你想点击它。在函数中使用它。
var electron = require('electron');
var window = electron.remote.getCurrentWindow();
window.setFullScreen(true);
答案 1 :(得分:1)
假设您要单击某个按钮以启用“全屏”。以下功能具有将屏幕切换为全屏的功能。您所需要做的就是单击按钮。
const handleFullScreen =()=>{
remote.getCurrentWindow().setFullScreen(true)
}
请注意,我正在使用遥控器,因为此功能是在“渲染器”中触发的,而“渲染器”是我最大化屏幕的按钮。