2016-08-21 27 views
2

我努力让自己在点击应用窗口全屏,但得到以下错误main.js:29 Uncaught TypeError: Cannot read property 'setFullScreen' of undefined电子集全屏的onclick

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

回答

7

在创建窗口对象,您可以设置全屏幕。这里

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); 
+0

我要上点击全屏默认情况下不 – ingsaurabh

+0

感谢它的工作,你可以点我一些教程学习电子,因为大多数的例子我在网络上找到使用电子旧的版本,所以也没有什么帮助 – ingsaurabh

+0

哦对不起,当我开始时,我遇到了同样的问题,只是检查文档并询问我在这里学到了如何处理一些问题。 –