473,395 Members | 1,999 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Relative paths in .js file

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!
Jul 23 '05 #1
3 2659
epigram ha scritto:
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 use this solution, too

Bye
Jul 23 '05 #2
Il Mon, 27 Jun 2005 11:03:18 -0400, epigram ha scritto:
I've got a javascript menu that uses an external .js file. 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. Any ideas would be much appreciated.


in the external .js file refer to location.pathname and act consequently

--
Firefox, il browser sicuro, veloce, affidabile.
<http://snipurl.com/ftpi>
Jul 23 '05 #3
If you reference all your src and href urls from the root (with a leading
slash) they will link correctly.
For instance:
If you want to reference 'http://www.yourhost.com/shared/somefile.gif' from
the root, from the "/shared/" directory or from deep in some other
directory, use:
" src='/shared/somefile.gif' ".
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Doug | last post by:
If I were to write an include with a relative path like include("../conf/config.php"); What is the use? As far as I understand it, the path is relative to the first script that is called by...
7
by: mark | last post by:
I am designing a website at the moment and looking at the difference between relative and absolute url links which is driving me crazy! I would like to use relative paths, but it is proving very...
5
by: jason | last post by:
Can anyone help me find a solution to quickly working out relative paths to a folder in the root of my server... Although it easy when you go - say - two levels down: .../includes it...
7
by: Rizaan Jappie | last post by:
is it possible to get the relative path based on a absolute path in c#? *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
2
by: Joe | last post by:
Hi, can someone tell me how to set up relativ paths in VS2003 C++ ? I have some source with a tree directory structure that segments include files in various directories: #include...
19
by: Jerry M. Gartner | last post by:
Greetings: What is the best way to resolve paths within a document regardless of what path it is opened under? For example: I have x.php and it contains <img src="images...">, (amongst other...
8
by: JJ | last post by:
I'm confused about paths. I have a functionn that uses the mappath method, which I think requires a virtual path (is that the same as a relative path?). But this doesn't always work as the...
2
by: BD | last post by:
Hi there. Using 8.2 on Windows. I have a situation where I have a db backup, which I want to deploy to a group of developer workstations. The target directory for the database files will be...
2
by: Peted | last post by:
Hi i have a circumstance where a user unzips a file, with a certain layer of directories to get to a textfile. So in any directory on the HDD they may end up with something like ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.