Tim,
Just read self.location.href to figure out how many directories deep the
page into which the script being loaded is, relative to the web root,
then prepend that many "../" 's to the links you're pulling out the array.
If you call self.location.href from inside the script, it will give you
the URL of the page the script's loaded into, and not the URL where the
.js file is located.
Something like this ought to work:
var webRoot = "http://www.mysite.com/";
var url = (self.location.href).replace(webRoot, "");
var urlArray = url.split("/");
var numSlashes = urlArray.length;
var prefix = "";
for(var i = 0; i < numSlashes; i++)
prefix += "../";
imgPath = prefix + imgPath;
Replace the value for webRoot with your's site homepage directory URL.
imgPath is the path to your image(s) from the web root.
*Warning*: code sample written entirely off the top of my head at the
end of a long day; not guaranteed to work without some tweaking, but
hopefully it'll get you going in the right direction.
Good luck.
j.
> Subject: linking to files from inside a external js
> From: "Tim Trepanier" <ttrepanier@n...>
> Date: Thu, 6 Mar 2003 19:45:15
> X-Message-Number: 10
>
> I've made an external js that displays some gifs on a rotating basis. In
> the js the gifs url links are part of an array. Then the link information
> from the array is used to write out the img link.
>
> This works fine for pages from the root directory. For pages in
> subdirectories the link breaks, as each sub directory level would require
> an additional "../" to go up to the image.
>
> How do i make an external js that will find the image regardless of how
> many subdirectories the page is coming from?
>
> Thank You!
--
jon stephens
<zontar@m...>
http://hiveminds.info/ HiveMinds Group
http://phpuddi.sourceforge.net/ phpUDDI Project
http://www.wrox.com/ Wrox Press "Programmer To Programmer"
http://www.glasshaus.com/ glasshaus "Web Developer To Web Developer"