电子设置全屏点击

ing*_*abh 4 javascript electron

我试图点击应用程序窗口全屏,但得到以下错误 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)
}
Run Code Online (Sandbox Code Playgroud)

Pau*_*val 11

您可以在创建Windows对象时设置全屏.

const {BrowserWindow} = require('electron');
let win = new BrowserWindow({width: 800, height: 600, fullscreen: true});
Run Code Online (Sandbox Code Playgroud)

在这里查看在制作窗口Electron BrowserWindow时可以添加的选项

我的不好,我忘了你想点击它.在一个函数中使用它.

var electron = require('electron');
var window = electron.remote.getCurrentWindow();
window.setFullScreen(true);
Run Code Online (Sandbox Code Playgroud)