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: Saturday July 14 2012 - 06:07:22

server relative paths for the .js files?


Poster: Twill
Dated: Friday August 1 2003 - 7:47:31 BST

hi all.

Other people have asked this as well, but either have not gotten a response, or not gotten one that has worked for me.

I am currently running RC3 because RC4 added some odd boxes around my menus.

My problem is that I cannot seem to get the src link right when I put my .js files in a different folder than my .html (.php) files

Right now I have <SCRIPT language=JavaScript src="/home/me/public_files/java/milonic_src.js" type=text/javascript></SCRIPT>

I have tried every variation on that I can think of, including trying src="http://......"

Anyone have any ideas?

relative paths


Poster: cubefree
Dated: Saturday August 2 2003 - 0:49:09 BST

I added this to my global.js file for my site, and it worked. I use a global.js file to store many other (non-menu) things regarding the site:


Code:

<script language="javascript" src="scripts/global.js"></script>


// Remove any frames
if (top.location != self.location) {
  top.location = self.location;
}

var url = self.location.href;
url = url.toLowerCase();

// determine the server
var DOM   = '';
var local = 'website/';
var live  = 'prototype/';
((url.lastIndexOf(local) > 1) ? DOM = local : DOM = live )

// determine relpath, section of site and subdirectory variable
var endOfDOM = url.lastIndexOf(DOM);
var endOfURL = url.substring((endOfDOM + DOM.length), url.length);

// determine relpath, section of site and subdirectory variable
var path = '';
for (i=0; i<endOfURL.length; i++) {
  if (endOfURL.charAt(i)=='/')         { path += '../'; }
}



above local and live variables are test or production servers, then a live server

Further down you'll need to add the path to each img tag and url, e.g.

Code:
path+"images/nav/cmm_arrow2_off.gif" // and
"<img src="+path+"images/nav/proginfo_off.gif width=150 height=23 border=0>","show-menu=proginfo",path+"proginfo/default.htm swapimage="+path+"images/nav/proginfo_on.gif;offfunction=undefined;","Program Information",1


it's working for me at all tiers

Hope that helps,
Cubefree

Re: server relative paths for the .js files?


Poster: John
Dated: Saturday August 2 2003 - 6:53:47 BST

Twill wrote:
I am currently running RC3 because RC4 added some odd boxes around my menus.

Same thing happened to me. Turned out I had some border settings wrong. Check your array code carefully (it worked the way it was under RC3, even though the code was wrong).
Quote:
My problem is that I cannot seem to get the src link right when I put my .js files in a different folder than my .html (.php) files

scriptpath=""; does nothing more than point to the directory that contains the menu files.
Quote:
Right now I have <SCRIPT language=JavaScript src="/home/me/public_files/java/milonic_src.js" type=text/javascript></SCRIPT>

If that is supposed to be your scriptpath=""; (which your message flow seems to indicate) it is entirely wrong. Andy gives an example right in the code. Following what you have written you should have scriptpath="/home/me/public_files/java/";


Poster: Twill
Dated: Saturday August 2 2003 - 11:13:07 BST

cubefree, that looks a lot more confusing that I had hoped for...I have no idea what a global.js file is :-p

jgillett , I dont know where this scriptpath""; thing came from or what it is. I looked in the examples for this code, but couldnt find one.

Are you saying that my html should look more like:

<html>
<head></head>
<body>
<SCRIPT language=JavaScript scriptpath="/home/me/public_files/java/" type=text/javascript></SCRIPT>
<SCRIPT language=JavaScript src="my_array.js" type=text/javascript></SCRIPT>
</body>
</html>

because I dont really know where to put this scriptpath.

sorry for being dense :) I have looked, and tried to fix it myself.


Poster: Hergio
Dated: Saturday August 2 2003 - 14:28:37 BST

No no, there is code in your webpage that references the milonic_src file. You need to correctly specify where your page should look for that. Then you also need to reference the menuarray.js file from your page as well using the correct path. I.E...
Code:
<SCRIPT language=JavaScript src="http://www.yourdomain.com/home/me/public_files/java/milonic_src.js" type=text/javascript></SCRIPT>
<SCRIPT language=JavaScript src="http://www.yourdomain.com/home/me/public_files/java/menu_array.js" type=text/javascript></SCRIPT>

What this does is first imports MILONIC_SRC into your page and executes it. Inside of milonic_src, there is a variable at the top called scriptpath...this variable tells milonic_src how to import the correct menu code (it decides based on your browser), but it needs a path to your menus directory because as far as its concerned, the code at that point is executing in the same directory as your webpage and will look in that directory if its not specified, so you should put that in here as well. I.E.
Code:
scriptpath="http://www.yourdomain.com/home/me/public_files/java/"

This way, the right menu code will be imported from ...com/home/me/public_files/java/menudom.js or whatever. Your page then will import the menu_array.js page from that same directory because you wrote it out in your page.

Hope this helps some. I tried to step out the process of what its doing, and I hope I didnt confuse you.


Poster: Twill
Dated: Sunday August 3 2003 - 16:45:53 BST

Brilliant!!

You rock my world!! :)

I didnt even notice that I was supposed to change anything in milonic_src :oops:

thanks a bunch, you made my life a whole bunch easier :)


Poster: Hergio
Dated: Monday August 4 2003 - 2:07:57 BST

Glad I could help! :D

And don't tell my wife I'm rocking people's worlds now, okay? :) I was just trying to help. ;)


Poster: dickwuzinya
Dated: Monday August 11 2003 - 16:58:53 BST

Hello and thanks for the thread postings. I have a personal site with the new horizontal menu located at http://www.keyway.net/~lan/menu. I have the html code on the page as follows...

<html>
<head>


<SCRIPT language=JavaScript src="http://www.keyway.net/~lan/menu/milonic_src.js" type=text/javascript></SCRIPT>
<SCRIPT language=JavaScript src="http://www.keyway.net/~lan/menu/horizontal_data.js" type=text/javascript></SCRIPT>



</head>

<body scroll=auto >

</body>

</html>

I also have a page located at

http://www.keyway.net/~lan/menu/test/index.html

It has the same html code pointing to the same path but does not display the menu. Can someone please explain to me what I have done wrong to disable the page in the test folder from working and PLEASE how to resolve this .
In advance I thank you for yout assistance.
Dick W-


Poster: Hergio
Dated: Monday August 11 2003 - 19:21:26 BST

I just took a look at both sites and they both displayed menus, so I am assuming you figured it out. My guess was you had a problem with your script path variable not being set to the correct directory even though your HTML code was dead on. Best of luck from here forward.


Poster: Rickstre
Dated: Thursday November 18 2004 - 1:04:17 GMT

The structure of my site is

http://www.sitename.com
.....htdocs
........root
........libs
..........navbars
.............menu.inc.php

(root and libs are on the same level, but navbars is below libs)

The code in menu.inc.php is:
Quote:
<script type="text/javascript" src="http://www.protonic.com/libs/navbars/milonic_src.js"></script>
<param copyright="JavaScript Menu by Milonic - http://www.milonic.com"></param>

<script type="text/javascript">
<!--
if(ns4)_d.write("<scr"+"ipt language=JavaScript src=http://www.protonic.com/libs/navbars/mmenuns4.js><\/scr"+"ipt>");
else _d.write("<scr"+"ipt language=JavaScript src=http://www.protonic.com/libs/navbars/mmenudom.js><\/scr"+"ipt>");
-->
</script>
type=text/javascript></SCRIPT>
?>
</head>
<body>
<script language=javascript>
<?
include("$DOCUMENT_ROOT/libs/navbars/menu_data.js.php");
?>
</script>


The menus is called by index.php in "htdocs"

Portion of index.php:
Quote:
<?
if ($frames) {
?>
<html>
<head>
<title>pagename</title>
</head>
.
.... No frames message
.
} else if (!$index) {

?>
<script language="javascript">
<!--
top.location.href='http://www.sitename.com/root/index.php?frames=true';
//-->
</script>
<?
exit;
}
?>
...........html code......
<?
require("$DOCUMENT_ROOT/libs/navbars/menu.inc.php");
?>
..........more HTML code....
"DOCUMENT_ROOT" above = 'http://www.sitename.com"

I also have tried prefixing the milonic_src.js, mmenuns4.js, and mmenudom.js files with all forms of:

http://www.sitename.com/libs/navbars/
/libs/navbars/
/navbars/
and even...http://www.sitename.com/htdocs/libs/navbars/ (though htdocs should not be necessary since this is root).

However, unless I place all files into the directory fron which a menu is called I get a JS error that indicates that the milonic_source.js file (and other js files) was not found pointing to the directory from which the script is run. Indeed if I place the three js files in the directories from which the script is run the menu works. However the relative path seems to be ignored.

I am NOT the original author of the site but now am charged with maintaining it. I presume the line in index.php:
Quote:
top.location.href='http://www.protonic.com/techs/index.php?frames=true';
is causing this problem. However this seems to be needed for authentication of the site.

Anyone have a method that can be used to fix this problem? AAARRRAAAGGGHHHH! :!: :!:

BTW since the site on which this is located is password protected if you need the URL I will have to set up a temporary login and password.