Hello I’m having some trouble with the following code within my Index.html file:
This works when my
Index.html file is in the same folder as
clock.js. Both Index.html and clock.js are in my root folder.
But when my index.html is in these different directories clock.js does not load:
What can I put as the ‘SRC’ so that it will always look for
clock.js in the root folder?
Thanks in advance!!
Note the forward slash.
Use an relative path to the root of your site, for example:
If clock.js is on
If it’s on your domain root directory:
The common practice is to put scripts in a discrete folder, typically at the root of the site. So, if clock.js lived here:
then you could add this code to the top of any page in your site and it would just work:
Piece of cake!
The leading slash means the root directory of your site. Strictly speaking,
Capitalization of tags and attributes is also widely discouraged.
be careful it’s root of the domain.
P.S. and please use lowercase for attribute names.
If you have
<base href="https://stackoverflow.com/" />
It’s will not load file right. Just delete it.
static. It should look something like this:
/ProjectName /static clock.js /templates index.html main.py
And then refer to the js file as following:
This will call the clock.js which you put in the root of your web site.