49

私は (以前の atom-shell) を使用しており、最小限のフレーム ウィンドウを使用して、3 つの OSX ウィンドウ ボタン (閉じる、最大化、最小化) がHTML ページElectronから見えるようにしたいと考えています。

クロムレス、フレームレス ウィンドウを定義するときに、Electron オプションframeをに設定します。falseBrowserWindow

そして、次のようなもので閉じるボタンを処理できると思いました:

<a btn href="#" id="close" onclick="window.top.close(); return false"></a>

残念ながら運が悪い。これを達成する方法はありますか?

4

3 に答える 3

3

私は自分のウィンドウを宣言しました:

const electron = require('electron')
const path = require('path')
const BrowserWindow = electron.remote.BrowserWindow

const notifyBtn = document.getElementById('notifyBtn')

notifyBtn.addEventListener('click',function(event){

    const modalPath = path.join('file://', __dirname,'add.html')
    let win = new BrowserWindow({ webPreferences: {nodeIntegration: true}, frame: false, transparent: true, alwaysOnTop:true, width: 400, height: 200 })
    win.on('close',function(){win = null})
    win.loadURL(modalPath)
    win.show()

})

そしてこれを閉じるために:

const electron = require('electron')
const path = require('path')
const remote = electron.remote

const closeBtn = document.getElementById('closeBtn')

closeBtn.addEventListener('click', function (event) {
    var window = remote.getCurrentWindow();
    window.close();
})
于 2019-12-19T16:17:41.223 に答える