Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

159
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda