PDA

View Full Version : Is there a way to get around hard coding URLs


newkid
09-29-2004, 12:20 AM
-- This one is kind of hard to explan if you have questions let me know please.

** Just starting a Re-Write on our intranet site (isnt life fun :eek: ) **
I have an Intranet site with alot of pages on it (quite counting at a 100) so I was thinking of setting up a header and footer that I would include so I would not have redundant code thru out the site and in the case of the footer, so I wouldn't have to change it on every page when it is updated.

<!--#INCLUDE file="Header2.htm"-->

***Header2.htm***

<DIV id="header" >
<DIV class="content">
<SCRIPT type='text/javascript'>
function Go(){return}
</SCRIPT>
<SCRIPT type='text/javascript' src='Bin/TopMenu_var.js'></SCRIPT>
<SCRIPT type='text/javascript' src='Bin/menu_com.js'></SCRIPT>
<TABLE border="0" width="100%" cellspacing="0" cellpadding="0" height="93">
<TR>
<TD height="93" width="10%" valign="middle" align="center" background="images/Menu/MenuHeader1.gif"></TD>
<TD height="93" width="84%" valign="bottom" align="center" background="images/Menu/MenuHeader2.gif">
<DIV id="headerline1">
<SCRIPT language="JavaScript1.2">
var months=new Array(13);
months[1]="January";
months[2]="February";
months[3]="March";
months[4]="April";
months[5]="May";
months[6]="June";
months[7]="July";
months[8]="August";
months[9]="September";
months[10]="October";
months[11]="November";
months[12]="December";
var time=new Date();
var lmonth=months[time.getMonth() + 1];
var date=time.getDate();
var year=time.getYear();
document.write("<left>" + lmonth + " ");
document.write(date + ", " + year + "</left>");
</SCRIPT>
</DIV>
<DIV id="headerline2">
Ridley Inc. Extranet
</DIV>
</TD>
<TD height="93" width="6%" valign="top" align="center" background="images/Menu/MenuHeader3.gif"></TD>
</TR>
</TABLE>
</DIV>
</DIV>



- included files are currently in the root folder
- Here's my problem, due to folder (directory) structure I was thinking about hard-coding URLs for sripts, graphic files etc because "images/menu/menuheader3.gif" will not work if the page I'm working with is 4 levels deep (IE. root/dept/IT/help)
- But If I hard code the URLs for example to "http://localhost/images/menu/menuheader3.gif" which covers me wether the page is in root or 4 levels deep, will be a pain because then I would have to change all the URLs http://localhost to http://www.mysite when I post site up to production server


1. Am I totaly nuts for doing this :o ?
2. Is there a way to store Site URL to a variable?
3. Is there a better way, or differenty way that I should be doing this?
4. Does it really make a difference if there is alot of redundant code on the site, should I just say what the heck, put the code on each page and hope the header portion never changes, well at least until I find a new job ;) ?
5. or is there some way to indicate root rather then ../../../../ to move backwards in the directory structure?


Thanks in advance for any help

J.C.
To learn is a good thing and today I hope to learn somthing new!!

newkid
09-29-2004, 02:10 AM
Ok did some reading in my Beginning Active Server Pages 3.0 book (love it when I'm stuck at work while the wife is out bowling ....... :thumbsup:

Figured out how to use server Variables (Server Name) to get what I need for my URL but would still like comments on questions 1, 3, 4, 5

Thanks
J.C.


1. Am I totaly nuts for doing this ?
3. Is there a better way, or differenty way that I should be doing this?
4. Does it really make a difference if there is alot of redundant code on the site, should I just say what the heck, put the code on each page and hope the header portion never changes, well at least until I find a new job ?
5. or is there some way to indicate root rather then ../../../../ to move backwards in the directory structure?

A1ien51
09-29-2004, 02:43 AM
easiest way is to have a server side variable that you can pass from page to page. If you were using .NET I would say use your web config file.


Eric

newkid
09-29-2004, 04:42 AM
Thanks A1ien51, pulled one of those can't see the forest for all the trees. Was a good exercies in using Server Variables.

Still would like feed-back on way I am using the include for a global code, from any one that would care to comment.

Thanks
J.C.

daltonlp
09-29-2004, 05:34 PM
"images/menu/menuheader3.gif" will not work if the page I'm working with is 4 levels deep

But /images/menu/menuheader3.gif will work.

If the URL starts with "/", it does exactly what you want--start at the root.