Thanks for the inputs. Your comment number 3 below brings to part of my
problem, and while I'm not even sure if I can explain it right I'm going
to try. Please forgive any lapses in proper web syntax...
I am trying to test a new menu script on my local test machine, which
sites on my home network. It's not running IIS (can't bring myself to
spend $200 upgrade to XP Pro a WinXP Home machine that I just paid $100
to upgrade from WinME less than a year ago), so none of the ASP stuff
will work, but it is running Apache/PHP and most of it works well enough
for me to do at least some testing. The menu is all JavaScript/DHTML so
I'm fine.
Anyway, there are some .js files that need to be called from every page
that has a menu. For all the pages in the root of my web, all is well,
but for those pages that live one level down the relative URLs break.
I publish the actual site to
www.mysite.com. The way the directory
structure works on the test machine on my home network (I installed
xampp), you publish (copy, actually) the web to an htdocs directory and
then browse to it at
http://ip_address/mysite/. A page in the root
directory would be browsed at
http://ip_address/mysite/page.htm.
Since the .js files must be called to each page, and since I absolutely
do not want to try to make different .js files depending on where in the
directory structure a page lives, I'm trying to use relative URLs to
point to the scripts and to the images that the script loads. My home
network server, though, considers
http://ip_address/ to be the root (I'm
guessing here), so if try to go back one directory it looks for a
page/file that doesn't exist.
Let me give an example:
A page on the live server is at
www.mysite.com/news/page.htm.
The script (we'll use just one as an example) is at
www.mysite.com/scripts/menuscript.js.
The image file is at
www.mysite.com/images/image.gif.
Let's talk about the .js file. When I call it from a page in the root
web I use:
<SCRIPT LANGUAGE="JavaScript" src="scripts/menuscript.js"></SCRIPT>
and that works, but it won't work when I call it from news/page.htm.
For that I use:
<SCRIPT LANGUAGE="JavaScript" src="../scripts/menuscript.js"></SCRIPT>
and that works. It's a bit of pain to have to use a different script
call depending on where the page lives, but it's manageable. The Jimco
add-in will not work for me here, because the calls have to be within
the <body> tag and Scripter puts them in the <head> tag.
What I can't fix is the calls to the image files. They get called from
within the .js file. The image files (and page URLs, too) are included
as part of variable declarations or whatever they're called. So, we're
finally to the part I can't figure out, and that's the syntax to use to
call these files so that it will look in the right place whether the
site is published to the live server at
www.mysite.com or to the test
server at ip_address/mysite/
I tried to use a server-relative URL, as in /images/image.gif, and I
think that would work on the live server, but on the test server it
tries to find a file at ip_address/images/image.gif instead of at
ip_address/mysite/images.gif. The same thing happens if I use
.../images/image.gif. If I use an absolute URL it would have to be
different for each server.
I'm going to flatter myself and say I understand why each server behaves
as it does, but I can't think of a way to fix it. Is my test server
mis-configured? xammp configured it, but I could try to change it if
that would help. I actually think I know how to write and make it work
on the production server, but if I'm wrong the site will have no
navigation bars while I debug it, and I would get dirty looks from my
client, who also happens to be my wife.
Other than re-configuring the test server, is there maybe a way to
dynamically built the link called from the .js file by somehow examing
the server and then using JavaScript to concatenate strings to point
everything in the right direction? That sounds a little over my head,
but I thought I'd ask.
Thanks for reading this far. Comments welcome.
Randy
Randy Morgan