How to pass parameters from main process to render processes in Electron

前端 未结 7 849
隐瞒了意图╮
隐瞒了意图╮ 2021-02-13 02:30

I have an Electron app that can open different windows.

On app launch the app open a set of window(s) (that load the same HTML and JS files) but with params to change ea

7条回答
  •  盖世英雄少女心
    2021-02-13 02:34

    Using query string along with win.loadFile(),

    // main process or renderer process 1
    data = {"age": 12, "healthy": true}
    
    let win = new BrowserWindow({
            webPreferences: {
              nodeIntegration: true
            }
          });
    
    win.loadFile("public/print.html", {query: {"data": JSON.stringify(data)}});
    
    // renderer process 2
    const querystring = require('querystring');
    let query = querystring.parse(global.location.search);
    let data = JSON.parse(query['?data'])
    

提交回复
热议问题