I've got a javascript menu that uses an external .js file. In the .js file,
there is a function that gets called by each of my .html pages to build up
the menu for the page. The way I want to structure my site is to put my
main index.html file in the root folder, and then have subdirectories for
various logical sections of my site that will contain related .html files.
I was hoping that the paths in the .js file would be relative to the
directory the .js file was located in (as CSS files appear to do), but that
doesn't appear to be the case. It appears the relative path is relative to
the directory the html file is in.
So, the problem is if I make the relative paths, in the .js file, work for
the main index.html file, it doesn't work for any of the .html files in the
subdirectories, or if I get to work for the files in the subdirectories, it
doesn't work in the main index.html file. I'm just looking for a best
practice way to solve this problem. One way I thought about doing it was to
put a parameter into the menu-building function that would indicate if the
calling html "file" was in the root directory or one of the subdirectories.
I also realized that I could put the main index.html into a subfolder itself
and that would solve the problem, but then I believe I'd have to put some
default html file in my root and redirect to the "real" default page for the
site. I'd like to avoid that option.
Any ideas would be much appreciated.
Thanks!
there is a function that gets called by each of my .html pages to build up
the menu for the page. The way I want to structure my site is to put my
main index.html file in the root folder, and then have subdirectories for
various logical sections of my site that will contain related .html files.
I was hoping that the paths in the .js file would be relative to the
directory the .js file was located in (as CSS files appear to do), but that
doesn't appear to be the case. It appears the relative path is relative to
the directory the html file is in.
So, the problem is if I make the relative paths, in the .js file, work for
the main index.html file, it doesn't work for any of the .html files in the
subdirectories, or if I get to work for the files in the subdirectories, it
doesn't work in the main index.html file. I'm just looking for a best
practice way to solve this problem. One way I thought about doing it was to
put a parameter into the menu-building function that would indicate if the
calling html "file" was in the root directory or one of the subdirectories.
I also realized that I could put the main index.html into a subfolder itself
and that would solve the problem, but then I believe I'd have to put some
default html file in my root and redirect to the "real" default page for the
site. I'd like to avoid that option.
Any ideas would be much appreciated.
Thanks!
Comment