0

I've this simple index.html

<html>
<head>
    <title>Title</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
    <script>
        alert("Hello World");
    </script>
    It's
    <script src="/js/date.js"></script>
</body>
</html>

which should recall date.js

document.write(new Date());

But unfortunately the date is not printed by the javascript.

  • What's wrong?

Note that if I put date.js in the same folder of index.html (that isWEB-INF), if I write <script src="date.js"></script> it works properly.

EDIT: This is the Project's hierarchy: Project's hierarchy and this is the output: Bad output

HeyBoo
  • 135
  • 1
  • 1
  • 8
  • 1
    Does the alert show up? Have you checked the console for errors? – j08691 Oct 25 '19 at 15:22
  • Hey, it should work if you change the path to `` If source packages is a folder of course – Anima Oct 25 '19 at 15:24
  • your javascript file is in different location. so the relative address from where your index.html is : ""../Source Packages/js/date.js"". change the src property to the correct address and you will be fine. – rez shahr Oct 25 '19 at 15:30
  • If I understand the folder structure right: this `` or this `` should work. Also you are missing close ` – ambianBeing Oct 25 '19 at 15:36
  • The alert shows up correctly and if I change date.js location and putting in the same location of the index.html, date.js works properly, but I don't want them to be in the same package – HeyBoo Oct 25 '19 at 15:53
  • @ambianBeing your solution does not work – HeyBoo Oct 25 '19 at 20:08
  • @HeyBoo Have mentioned that if I understood the directory structure correctly. Could you edit the heirarchy to be presented in the question to like [this](https://stackoverflow.com/a/347577/6082280) . Is the **js folder** not in the same directory as `index.html`. Is it inside **Source Packages** folder. – ambianBeing Oct 25 '19 at 20:13
  • js folder is in src package folder – HeyBoo Oct 25 '19 at 20:16
  • @HeyBoo Are you calling src as Source Packages in the question (if yes, that is little misleading). Would suggest to please post a screenshot of the directory structure in the question to provide a better visibility. – ambianBeing Oct 25 '19 at 20:25
  • Just done it: post edited with further information – HeyBoo Oct 26 '19 at 08:23
  • This solution does not work :( – HeyBoo Oct 26 '19 at 20:04
  • @HeyBoo Since I tested it exact folder structure it worked as one of the asnwers suggest too (we cannot reproduce this). I think your js file is in some nested package or something (Why?). I suggest what you can do to debug is.. bring that js file to same directory as `index.html` and then move the `js` file one by one to the directory `/js` while changing the `src` (helpers: `./` same directory and `../` one directory backwards and so) this way you might find what the problem is. – ambianBeing Oct 26 '19 at 23:13

1 Answers1

0

You can use "../" to "go backwards" in folders so it would be

<script src="../Source Packages/js/date.js"></script>
Txoka
  • 13
  • 6