javascript document root relative

I have a javascript menu that I would like to use only once across the whole site.  My site looks like this:


So the links in my script are like:

I would like to have the javascript file reside on the highest level but when I do the links wont work on the lower levels.  This is all about the document's relative path.  Is there anyway to solve this so that the menu link (from the script file) in folder2/foldera/file3.html would point back to ../../folder1/file.html?

make sense?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Put your script relative to server root.
code your links from the root:


Also look whether <base> tag is of help to you:

Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

there's a problem with IE (well it's a matter of taste probably) that IE interpretes links to a certain frame relative to the current location of the document in the frame. Even if the links are clicked from another frame. Netscape/Mozilla takes link relative to the location of the document where the click is being done. It's been this way forever, and i don't know why they never get on speaking terms about this.

- make sure that every link is defined from the root (start with "/")
- use the <base> tag (as NetGroove says)

maybe some other depending on the situation
srobiaAuthor Commented:
Sorry none of those really help out.  My javascript file generates the menu.  I can link to the javascript files just fine.  BUT it is the menu that is generated by the javascript that needs to change with the document location.  Is there anyway to do this within javascript?  Basically, find the current document's location then traverse back to the server root and generate a dynamic menu that will automatically make all the links valid.
Your script can read the actual window location and document location.
According to actual location your menu can adapt, for example by comparing to a common base for script and for the page using the script.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Sorry, I just noticed that I repeated your last sentence.
Now when you know that actual window URL is readable by your script, then what is your question???

srobiaAuthor Commented:
How do you make the script use the current location to dynamically build the menu?  based upon document.location I was thinking you could parse the string and find the "/" and build a dynamic ../  make sense?
Of course make sense. But what is your question?
You can make it any way around.
Decide what you want and I can show you how to do.

If your site is partially online or if your sources are les then let say three hundred lines, then post it here.
srobiaAuthor Commented:
I think I figured it out.  I found enough documentation out there to make it a dynamic menu.  thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.