How to call a JavaScript function on a web page rendered by Electron?

前端 未结 3 1723
滥情空心
滥情空心 2020-12-28 16:45

I\'m trying to write a wrapper for Twitter using Electron (formerly Atom Shell).

My main.js file (it looks almost identical to the \"Hello World\" examp

3条回答
  •  甜味超标
    2020-12-28 17:15

    The proper way is to use contents.send('some_js_Method','parameters') to invoke a javascript method in a web page from main.js

    // In the main.js
    const {app, BrowserWindow} = require('electron')
    let win = null
    
    app.on('ready', () => {
      win = new BrowserWindow({width: 800, height: 600})
      win.loadURL(`file://${__dirname}/index.html`)
      win.webContents.send(some_js_Method', 'window created!') //calling js method (async call)
    })
    
    
    //in index.html
    
    
      
    
    
    

提交回复
热议问题