Milonic provide full featured pull down web menus for some of the worlds largest companies
click here to see what it can do for you

Download Milonic DHTML Menu
Buy Milonic DHTML Menu

Back To Start Of Archive
Taken From The Forum: Help & Support for DHTML Menu Version 5+
Forum Topic: Click to view post
Last Updated: Thursday February 8 2018 - 06:02:19

Problem with url and relative paths

Poster: Gary
Dated: Friday November 14 2003 - 2:45:10 GMT

I'm using asp to generate dynamic pages. Each page has the same header at the top, and the milonic menu is included in that header. This works well as long as the .asp file is located in the root directory. But some of my files are not in the root directory, and that causes a problem. An example should make the problem clear:

I have a guestbook page "guestbook.asp" located at "ROOT/guestbook/guestbook.asp". On the .asp files located in the root directory, a relative link (e.g., url=/guestbook/guestbook.asp?action=view) works fine. But if, for example, I view the guestbook, and then decide to sign it, the relative link (url=/guestbook/guestbook.asp?action=sign), tries to access "ROOT/guestbook/guestbook/guestbook.asp", which, of course, doesn't exist.

Is there some way to specify a default root directory so that relative paths will work no matter what directory they're executed from?

Gary [/i]

Poster: bobwill
Dated: Friday November 14 2003 - 13:38:57 GMT

How about posting the URL so we can take a look.

Here is an idea that might help.

Set up a variable in your data file that defines your ROOT directory.

var baseurl="http://www.myroot.coml/";

and then you can add to each address.

aI("text=Scores & statistics;url="+baseurl+"guestbook/guestbook.asp?action=sign;status=Guest Book Signing;");

I did not put a "/" before the subdirectory "guestbook" because it is already part of the "baseurl" definition.

Could I use an environment variable?

Poster: Gary
Dated: Saturday November 15 2003 - 15:16:12 GMT

bobwill wrote:Set up a variable in your data file that defines your ROOT directory.

That's a great idea! Thanks. That solves the problem, but I still have to hard-code the root address in the "menu_data.js" file. I'd like to set the root variable automatically by accessing an environment variable. That way, the drop-down menus will work whether the "menu_data.js" file is located on my laptop or on the Internet (without me having to remember to reset the root variable from "http://localhost..." to "http://www.domainname...").

But I can't seem to find any information on accessing environment variables in java. Apparently java doesn't support such a thing. Do you (or anyone else) know how I might use asp to pass an environment variable to java?

Thanks again!


Poster: Hergio
Dated: Sunday November 16 2003 - 6:22:42 GMT

Could you post a URL because as far as I can tell, what you are doing should work. In my everyday use of the menu at my companies intranet site, I use absolute URLs all the time. My menu items have a url item like so... url=/dir1/page1.asp and this menu item referecing this page works no matter what page I have the menu on. Why its taking the current directory and appending your URL string, I have no idea....definetly you sould send us a URL.

Secondly in javascript, there really is no such thing as an environmental variable. But you can define variable in one js file, include that and then when you include another js file into that same page, you can reference variables that were defined in previous js includes.

Say you have
<script src='script1.js'></script>
<script src='script2.js'></script>
If in script1, you say SOMEVAR = 3; then later in script2 you can have something like if( SOMEVAR == 3){} even though you did not specifically define SOMEVAR inside of script2, you did it in script1. But obviously for script2 to work then, it needs script1 (or SOMEVAR defined). Use this to your advantage in your pages. As you know, every page that has the menu FIRST imports the milonic_src file, right? So at the top of that file define a variable, more specifically your ROOTURL variable. Then in your menu_data file, you can access ROOTURL as bobwill said above and it will work and you only have to change one variable in your code when you upload from dev server to production server. Hope this helps. ;)

Poster: John
Dated: Sunday November 16 2003 - 6:33:34 GMT

Hergio wrote:Could you post a URL because as far as I can tell, what you are doing should work.

I thought the same thing, as I code that way as well. Was waiting for him to come back with the URL as BW had requested, but it never came.

Poster: Gary
Dated: Monday November 17 2003 - 6:07:02 GMT

Sorry, but no URL exists yet. The website I'm developing exists only on my laptop so far. I've set a variable to identify the proper root directory, and that works fine. I'll just have to remember to reset it when I eventually move the site to the Internet.

Thanks for your help!