Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/431.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,我试图在单击时使应用程序窗口全屏显示,但出现以下错误main.js:29未捕获类型错误:无法读取未定义的属性“setFullScreen” main.js const electron = require('electron') // Module to control application life. const app = electron.app // Module to create native browser window. const BrowserWindow = el

我试图在单击时使应用程序窗口全屏显示,但出现以下错误
main.js:29未捕获类型错误:无法读取未定义的属性“setFullScreen”

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)
}

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

const {BrowserWindow} = require('electron');
let win = new BrowserWindow({width: 800, height: 600, fullscreen: true});
在这里检查在创建窗口时可以添加哪些选项

我的错,我忘了你想让它完全点击。在函数中,请使用此选项

var electron = require('electron');
var window = electron.remote.getCurrentWindow();
window.setFullScreen(true);

假设您要单击某个按钮以启用全屏。下面的功能用于将屏幕更改为全屏。你只要按一下按钮就可以了

 const handleFullScreen =()=>{
    remote.getCurrentWindow().setFullScreen(true)
}

请注意,remote我使用remote是因为此功能在渲染器中触发,而渲染器正是我最大化屏幕的按钮所在。

我想在单击时全屏显示,而不是默认设置。谢谢它起作用。你能给我指一些学习electron的教程吗?因为我在web上找到的大多数示例都使用较旧版本的electron,所以对不起,我刚开始的时候也遇到了同样的问题,只是检查了一下文档,问了一下这里我学会了如何处理一些问题。