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

155
Visualizações
How to use inline JavaScript inside HTML files?

I would like to use JavaScript tags inside HTML files in Electron.

I know I can use code like this in main.js:

webPreferences: { preload: path.join(__dirname, "preload.js"), },

And then import this script in HTML files like this:

<script>alert("This works!")</script>

But why can't I just use JavaScript like this inside HTML files:

alert("Why won't this work?");

There is a default meta tag in HTML when I follow Electron's quick start guide: <meta http-equiv="X-Content-Security-Policy" content="default-src 'self'; script-src 'self'" />

And this I guess disables executing inline JavaScript.

So my question is, is it bad practice to use inline JavaScript like this in Electron? Should this be avoided?

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

0

yes you can use javascript inside HTML files by using the script tag .

<script>
     //code goes here
</script>

now coming to use of inline javascript its not a good practice if you are creating a project because then it will be hard to maintain if you start working with multiple files.

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