电子设置全屏onclick
Electron set fullscreen onclick
我正在尝试让应用 window 在点击时全屏显示,但出现以下错误 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)
}
创建windows对象时可以设置全屏。
const {BrowserWindow} = require('electron');
let win = new BrowserWindow({width: 800, height: 600, fullscreen: true});
在此处查看您制作 window Electron BrowserWindow
时可以添加的选项
不好意思,我忘了你想让它在点击时充满。在一个函数中使用这个。
var electron = require('electron');
var window = electron.remote.getCurrentWindow();
window.setFullScreen(true);
假设您有一个特定的按钮,您想要单击它以启用全屏。 下面的函数实现了将屏幕更改为全屏的功能。您所要做的就是在单击按钮时调用它。
const handleFullScreen =()=>{
remote.getCurrentWindow().setFullScreen(true)
}
请注意,我正在使用遥控器,因为此功能是在渲染器中触发的,渲染器是我最大化屏幕的按钮所在的位置。
我正在尝试让应用 window 在点击时全屏显示,但出现以下错误 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)
}
创建windows对象时可以设置全屏。
const {BrowserWindow} = require('electron');
let win = new BrowserWindow({width: 800, height: 600, fullscreen: true});
在此处查看您制作 window Electron BrowserWindow
时可以添加的选项不好意思,我忘了你想让它在点击时充满。在一个函数中使用这个。
var electron = require('electron');
var window = electron.remote.getCurrentWindow();
window.setFullScreen(true);
假设您有一个特定的按钮,您想要单击它以启用全屏。 下面的函数实现了将屏幕更改为全屏的功能。您所要做的就是在单击按钮时调用它。
const handleFullScreen =()=>{
remote.getCurrentWindow().setFullScreen(true)
}
请注意,我正在使用遥控器,因为此功能是在渲染器中触发的,渲染器是我最大化屏幕的按钮所在的位置。