Saturday, 15 April 2017

How to load javascript in the browser window?

This is the standard way to create a window in Electron (from the docs);

let win;
function createWindow(){
  // Create the browser window.
  win = new BrowserWindow({width: 680, height: 420, frame: false, transparent: true, show: false});

  // and load the index.html of the app.
  win.loadURL(url.format({
    pathname: path.join(__dirname, 'test.html'),
    protocol: 'file:',
    slashes: true
  }));

  win.once('ready-to-show', function() {
    win.show();
  });


  // Open the DevTools.
  // win.webContents.openDevTools()

  // Emitted when the window is closed.
  win.on('closed', function () {
    // Dereference the window object, usually you would store windows
    // in an array if your app supports multi windows, this is the time
    // when you should delete the corresponding element.
    win = null;
  })

}

Works fine, but how can I load a bunch of javascript files, like jQuery etc, in the window context WITHOUT using <script> tags in test.html?

The reason I don't want to use script tags is because I can have many .js files and .html files and I don't want to update the html everytime something changes. I'd rather have them in the function that creates the window.



via thelolcat

No comments:

Post a Comment