Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

relative links in menu 1

Status
Not open for further replies.

JillC

Technical User
Joined
Jan 10, 2001
Messages
241
Location
AU
The website already had a javascript menu. In amending the site, I moved some files into directories. So now my file structure looks like this:
index.html
menu.js
bags/carrybags.html

etc.

The html pages include the following code:
<script language="JavaScript" src="../menu.js"></script>

The menu.js has code like this:

document.write('<tr><form action="index.html"><td>');
document.write('<input type="submit" value=" Home " onmouseover="this.className=\'buttonon\'" onmouseout="this.className=\'button\'" class="button"><br>');

document.write('</td></form><form action="../bags/carrybags.html"><td>');
document.write('<input type="submit" value=" Bags " onmouseover="this.className=\'buttonon\'" onmouseout="this.className=\'button\'" class="button"><br>');

While testing this script, it just breaks going between folder levels. If I start by previewing the index.html page then other pages within that level will load. But it won't go up a level - or if it does, then it won't come back down. So I have 4 menu items in the root and five menu items leading to five different folders. It worked find when everything was in the same folder. I have tried all sorts of alternatives with/without preceding dots and dashes and even tried \.\. but nothing works. It should be just a simple relative path, shouldn't it? The site is not online yet.

Your suggestions/help would be greatly appreciated.
 
Is this on a server? If it's not in a root directory/folder or the root of a domain on a server, then the ".." will always move the path up one directory/folder, even if it's in what will be the root of the domain once it's online.

If you're running the script locally, not through a web server, and it's not in the root directory of the drive, ".." means to move one directory higher, which will mess things up the same way.

Lee
 
No, it's not on a server. So, you're telling me to abandon this script? If I happen to be on a file in a directory, I can't get back to the root?
 
Yes, I could do that. I could also fill my entire filing cabinet with all my pieces of paper just higgeldy piggeldy with no folders, paper clips, staples, nothing to distguish one from the other. In fact I could just do away with a filing cabinet and just shove everything under the bed! [dazed]

The 5 folders are for different categories each with their own sets of files. Never mind. I understand CSS a little better than JS. I'll scrap the menu file and replace it with CSS.
 
I never told you to abandon the script, only that it wouldn't work the way you had it if it wasn't on a server, and asked about that to better answer your question.

Actually, you could add conditions in the script to concatentate the '../' if the page is in a subdirectory, and leave it blank if it's not.
Code:
var path = '';
if (location.href.indexOf('\/bags\/') > -1)
  {
  path = '../';
  }
//add more conditions here for directories

document.write('</td></form><form action="' + path + 'bags/carrybags.html"><td>');

Lee

 
Thanks, Lee. As I've not got into JS code, I decided to go back to what I know. I've set the menu up in a dwt file and applied CSS to it. This means I still only have one file to alter if the menu changes and looks nicer too.

Thanks for your input though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top