Estoy tratando de cambiar el archivo html utilizado en la aplicación Electron. Probé varias sugerencias aquí en StackOverFlow, pero no puedo lograr nada. Mi código es el siguiente:
principal.js:
<!DOCTYPE html> <html> <head> <script src="renderer.js"></script> </head> <body> <h1>One</h1> <button id="change">Change</button> </body> </html>
nuevo.html:
<!DOCTYPE html> <html> <head></head> <body> <h1>Two</h1> </body> </html>
principal.js:
const { app, BrowserWindow } = require('electron') const path = require('path') function createWindow () { // Create the browser window. const mainWindow = new BrowserWindow({ width: 800, height: 600 }) mainWindow.loadFile('index.html') mainWindow.openDevTools(); } app.whenReady().then(() => { createWindow() app.on('activate', function () { if (BrowserWindow.getAllWindows().length === 0) createWindow() }) })
renderizador.js:
const {BrowserWindow} = require('electron').remote const path = require('path') const newWindowBtn = document.getElementById('change') newWindowBtn.addEventListener('click', (event) => { let win = new BrowserWindow({ width: 400, height: 320 }) win.on('close', () => { win = null }) win.loadFile("new.html"); })
Estoy tratando de cambiar el archivo html a new.html una vez que uno hace clic en el botón en index.html.
puede usar location.href='new.html'
en esta función para cambiar de página en una ventana.