V
V
Vyacheslav_Shilov2019-11-17 04:06:08
JavaScript
Vyacheslav_Shilov, 2019-11-17 04:06:08

Why is the alert not showing in the browser?

5dd09d4d77cfb219728271.pngGiven:
Project on node.js.
It has three files: "app.js" - it creates and starts the server, it also renders the "index.html" page.
"index.html" - it links another js file - "index.js".
In "index.js", in turn, there is a line "alert("something");"
Question: why is the alert not displayed in the browser? Everything is fine with the server and other things.
However, when you write like this (directly in "index.html"): everything works
<script>alert("something")</script>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pashenka, 2019-11-17
@like-a-boss

app.js

var static = require( 'node-static' ),
    port = 4000,
    host = 'localhost',
    http = require( 'http' );


var file = new static.Server( './public', {
    cache: 3600,
    gzip: true
} );


var server = http.createServer( function ( request, response ) {
    request.addListener( 'end', function () {
        file.serve( request, response );
    } ).resume();
} );


server.listen( port, host, function() {
  console.log( `Listening at http://${ host }:${ port }` );
} );

A
Andrey Ololoshchenko, 2019-11-18
@veremii

Are you sure that your index.js file was found and loaded?
Try importing it in a relative path like
<script src="./index.js"> </script>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question