server relative paths for the .js files?

Having problems with DHTML Menu? There is usually somebody here who knows the answer.
Post Reply
Twill
Advanced
Advanced
Posts: 16
Joined: Tue Jul 08, 2003 6:47 am

server relative paths for the .js files?

Post by Twill »

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?
User avatar
cubefree
Super Advanced
Super Advanced
Posts: 82
Joined: Fri Aug 01, 2003 3:16 am
Location: Seattle, WA
Contact:

relative paths

Post by cubefree »

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: Select all


<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: Select all

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
User avatar
John
 Team
 Team
Posts: 5967
Joined: Sun May 19, 2002 8:23 pm
Location: Phoenix, AZ
Contact:

Re: server relative paths for the .js files?

Post by John »

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).
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.
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/";
John
Twill
Advanced
Advanced
Posts: 16
Joined: Tue Jul 08, 2003 6:47 am

Post by Twill »

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.
User avatar
Hergio
Milonic God
Milonic God
Posts: 1123
Joined: Wed Jun 12, 2002 7:46 pm
Location: Rochester, NY

Post by Hergio »

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: Select all

<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: Select all

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.
Dave Hergert
Software Engineer
"Helping to make the menu better, one :?: at a time."
Twill
Advanced
Advanced
Posts: 16
Joined: Tue Jul 08, 2003 6:47 am

Post by Twill »

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 :)
User avatar
Hergio
Milonic God
Milonic God
Posts: 1123
Joined: Wed Jun 12, 2002 7:46 pm
Location: Rochester, NY

Post by Hergio »

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. ;)
Dave Hergert
Software Engineer
"Helping to make the menu better, one :?: at a time."
dickwuzinya
Beginner
Beginner
Posts: 2
Joined: Mon Aug 11, 2003 9:28 am

Post by dickwuzinya »

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-
User avatar
Hergio
Milonic God
Milonic God
Posts: 1123
Joined: Wed Jun 12, 2002 7:46 pm
Location: Rochester, NY

Post by Hergio »

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.
Dave Hergert
Software Engineer
"Helping to make the menu better, one :?: at a time."
Rickstre
Beginner
Beginner
Posts: 6
Joined: Thu Nov 18, 2004 1:32 am

Post by Rickstre »

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:
<script type="text/javascript" src="http://www.protonic.com/libs/navbars/mi ... "></script>
<param copyright="JavaScript Menu by Milonic - http://milonic.com"></param>

<script type="text/javascript">
<!--
if(ns4)_d.write("<scr"+"ipt language=JavaScript src=http://www.protonic.com/libs/navbars/mm ... /scr"+"ipt>");
else _d.write("<scr"+"ipt language=JavaScript src=http://www.protonic.com/libs/navbars/mm ... /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:
<?
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:
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.
Post Reply