Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

591
Visualizações
How to change the used html file in Electron?

I am trying to change the html file used in the Electron app. I tried several suggestions here on StackOverFlow, but I am unable to achieve anything. My code is as follows:

main.js:

<!DOCTYPE html>
<html>
    <head>
        <script src="renderer.js"></script>
    </head>
    <body>
        <h1>One</h1>
        <button id="change">Change</button>
    </body>
</html>

new.html:

<!DOCTYPE html>
<html>
    <head></head>
    <body>
        <h1>Two</h1>
    </body>
</html>

main.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()  
    })
})

renderer.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");
})

I am trying to change the html file to new.html once one clicks on the button in the index.html.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

you can use location.href='new.html' in this function to change page in one window.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda