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

291
Vistas
External Javascript file not working in HTML

This is extremely basic but I'm unsure why this has stopped working. I have the following html file

<html>
<!doctype html>
<head>
  
   <script> document.write("this is working")</script>
   <p>this is working</p>

</head>
<body>
    <script src="test.js"></script>
</body>
</html>

and the following javascript file that is in the same folder as the html file

document.write("Hello World!");

The scripts and html within the html document work fine. However, the external javascript file does not get executed. I have tried with a variety of scripts in the js file and minor modifications to the html file. On a windows 10 computer.

Note this is not a repeated question, the other questions similar to this one were slightly different.

EDIT: Error in browser console states "not allowed to load local source" This may be a chrome security issue. EDIT: Same case in all browsers so doesn't seem purely related to chrome. Attempted all the fixes I could find but did not work.

EDIT: I tried using both node and python for the server.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Looks like you're loading the HTML file through file protocol (i.e. double-clicking the file and opening it in a browser). In that case, browser may deny to load any external resources (test.js script in your case) due to security. Load the HTML through HTTP protocol. It can be achieved numerous ways.

  • If you have PHP installed, simply running php -S localhost:80 within the project directory will spin up a local server, which you can browse by visiting http://localhost. It will then serve the index.html page by default.
  • If you have Node.js installed (thus npm, too), install http-server globally (npm i http-server -g). And afterthat, run http-server within the project directory. By default, it will spin up a local server on port 8080, so you'll be able to visit http://localhost:8080 and index.html will be served.

I tried the later one, and your above code worked perfectly fine.

about 4 years ago · Juan Pablo Isaza Denunciar

0

This is not a solution, but it is a work around if anyone has the same issue and a better answer is not produced.

Get the chrome extension "web server" and open that rather than running it through node, python, etc.

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