繁体   English   中英

如何使用 JavaScript 或 jQuery 或 ZA7F5F35426B9237411FCZ2317BZ 最小化浏览器 Window

[英]How to Minimize Browser Window using JavaScript or jQuery or Python

Trying to develop a small app using python flask and electron JS, basically i am using electron for only to run Flask Python Script by using (child_process & Spawn) in electron main.js file also using (LoadURL(http://localhost:5000 )) 而不是使用 (loadURL(index.html))。

I did close the Browser Window using simple (Window.Close()) function in separate JavaScript file which is linked in the body section, but cant figure out how to MINIMIZE the Browser Window using only JavaScript or Python in the same file linked in body .

不能为此使用 electron,因为我没有在 loadURL 中使用 index.html。

感谢我无法获得的所有帮助。

您应该使用预加载脚本进程间通信

就这么简单

// in the preload script
// you can access Electron's renderer process modules here

const { contextBridge, ipcRenderer } = require('electron')

// you should handle the IPC call in the main process
// and call Electron's browserWindow.minimize() function
contextBridge.exposeInMainWorld('minimize', () => ipcRenderer.send('minimize'))
// in the main process, you should have something like this

const {app, BrowserWindow, ipcMain} = require('electron')
const path = require('path')

function createWindow () {
  const mainWindow = new BrowserWindow({
    webPreferences: {
      preload: path.join(__dirname, 'preload.js')
    }
  })

  ipcMain.on('minimize', () => {
    mainWindow.minimize()
  })

  mainWindow.loadURL('https://example.com')
}

在您的 JavaScript 文件中,您现在可以调用window.minimize()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM