Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

relative/absolute paths....

Status
Not open for further replies.

PaulSc

MIS
Aug 21, 2000
148
GB
Hi (as usual :) ) I'm after a bit of guidance/help please....

I have a local html/javascript based image gallery "website" used to display my digital pictures.

it uses a javascript menu/navigation bar which I have on all pages but with the "site" spread across multiple folder levels I'm having to maintain 3 copies of the js code
which as the site/number of pictures I take grows is becoming a pain...

My site is fairly basic in that its got


[pre]
website (Top level html main menu page - js here)
year1 (gallery index with the js menu here too)
htmlp1 (thumbnail pages again with the js menu)
htmlp2
year2
htmlp1
htmlp2
year3
htmlp1
htmlp2
htmlp3
...
year 17 etc
htmlp1
htmlp2
sitefiles
js
css
images

in the js menu I refer to base images, urls etc via href/src tags and currently use relative references
i.e src='sitefiles/images/image1.jpg'
however whilst 99% of the code is then identical for the 2nd folder level pages i have to use
src='../sitefiles/images/image1.jpg'
and the lower level thumbnail pages
src='../../sitefiles/images/image1.jpg'
[/pre]

JavaScript:
document.write("    <li><a href='2002/00_General/default.htm'>		<img src='sitefiles/webimage/Odd_Small.png'>		<b> 00: General 2002</b> - General Pictures 						<img src='sitefiles/webimage/close.png'></a></li>");
document.write("    <li><a href='2003/00_General/default.htm'>		<img src='sitefiles/webimage/Odd_Small.png'>		<b> 00: General 2003</b> - General Pictures 						<img src='sitefiles/webimage/close.png'></a></li>");

I know I can probably use something like src="file://d:/website/sitefiles/images/image1.jpg' but that just seems to cause it to grow in size (3 times per gallery/sub gallery) and
this then becomes equally unmanageable....

So wonder if there's a "better/easier" way of achieving this so I can ultimately use a single piece of js on every page/throughout the site..?

Shout if you need more info and Thanks...

PaulSc
 
Could you have a variable pointing to the parent directory
Code:
var sitefiles = "../../sitefiles"
document.write(" .... <img src='" + sitefiles + "webimage/... ")
Alternatively
Code:
var sitefiles = Server.Mappath("/sitefiles")

Will runat="server" will work for you. I was thinking along the lines of
Code:
<img runat="server" src="~/sitefiles/....">
but I have never tried it in a document.write
 
but with the "site" spread across multiple folder levels

Just use 'root relative addressing' in that case and specify all paths from the site root.



Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.
 
Thanks for the suggestion(s)..I've got it working now...

I ended up using a "plugin" javascript (from and the 1st of xwb's examples to set some vars to pass in...

Chris, your way worked too, but only if site was run as a "web" site (i.e via IIS/localhost)..unfortunately (I should have said) that option isn't available to me at present so I needed it on a pure client based solution..

Thanks for the suggestions which all helped point me to a better way of doing this..

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top