Phan Vũ Tuấn Anh
Phan Vũ Tuấn Anh

Reputation: 33

Can't find .js files in Chrome Sources tab?

Thanks for giving this question a look. I'm an absolute newbie in JavaScript and just tried to learn JavaScript yesterday so my knowledge about this is pretty low. (Sorry for my bad English)

I tried to run a .html file with a .js file included in it but when i ran it with Live Server Extension, I can't see the .js file in the Page tab in Sources and I can't execute the .js file too. All I see is the index.html file. Is there any solution for this, guys?

This is my page with the Inspector turned on

These are my files displayed in Visual Studio Code

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>This is the title.</title>
</head>
<body>
    <h1>So this is the header</h1>
    <script scr='home.js'>
        alert('something')
    </script>
    
</body>
</html>

And home.js

alert('Do you see me?');

My file structure is very simple

2nd
├── home.js 
├── index.html

I've tried to

But still not working.

Upvotes: 3

Views: 1265

Answers (3)

Tofa Hossain
Tofa Hossain

Reputation: 21

Please add the source line at the end of the body tag. This will work, I believe.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>This is the title.</title>
</head>
<body>
    <h1>So this is the header</h1>


    <script scr='home.js'>
        alert('something')
    </script>

    <script src="home.js"></script>
</body>
</html>

Upvotes: 1

dongnhan
dongnhan

Reputation: 1768

Looks like you're serving only the index.html file not the whole directory. You could try to run Live Server from the root directory (which is 2nd in this case) or check out this npm package for setting up a simple http server https://www.npmjs.com/package/http-server

P/s: There is a typo in your script tag, src not scr

Upvotes: 1

SWAPNIL KUWAR
SWAPNIL KUWAR

Reputation: 422

The script should be loaded in HTML like this:

<script src="myscripts.js"></script>

Upvotes: 1

Related Questions