console报错:Cannot read property 'getCurrentWindow

index.js

const { app, BrowserWindow } = require('electron')
function createWindow () {
       win = new BrowserWindow({
           webPreferences: {nodeIntegration: true, NodejsenableRemoteModule: true, contextIsolation: false},
       })
    win.on('ready-to-show',()=> {
        win.show()
    })


      win.loadFile('index.html')

      win.on('closed',()=>{
             console.log('closed')
             win = null
      })
} 
process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true'

app.on('ready', createWindow)
app.on('window-all-closed',()=>{
       console.log('window-all-closed')
       if(process.platform !== 'darwin') {
          app.quit()
       }
})
app.on('activate',() =>{
       console.log('activate')
       if(win == null) {
             createWindow()
       }
})

 

 

index.html

<!DOCTYPE html>
<html>
  <head>
           <meta charset="UTF-8">
           <title>绿色</title>
            <script src="event.js"></script>
  </head>
   <body>
          <img src="H:/源图/led.jpg"/>
          <h2>书名:<i>《绿色的树叶》</i></h2>
          <br>
          <br>
          出版社:<u>人民日报</u>
          <br>
          <br>
          原价:<del>188</del>元  促销价:66元
          <br>
          <br>
      <button id="button" onclick="onClick()">进入锁定模式</button>
  </body>
</html>

event.js

const remote = require("electron").remote
function onClick() {
    const button = document.getElementById('button')
    const win = remote.getCurrentWindow()
    if(win.isKiosk()){
     win.setKiosk(false)
     button.innerText = "进入锁定模式"
    }
    else{
        win.setKiosk(true)
        button.innerText = "退出锁定模式"
    }
}

 console报错

 

刚开始学习electron,实在找不出问题在哪?希望路过的好心人帮忙一下 

electron 10中,修改了enableRemoteModule默认为false,我们需要手动将其修改为true

webPreferences配置参数enableRemoteModule:true来打开remote模块

https://blog.csdn.net/liu19721018/article/details/108922594

不一样的问题

不一样的问题