D&C Lug - Home Page
Devon & Cornwall Linux Users' Group

[ Date Index ][ Thread Index ]
[ <= Previous by date / thread ] [ Next by date / thread => ]

Re: [LUG] directories in javascript



On 12 May 2003 at 20:54, Neil Williams wrote:

> On Monday 12 May 2003 9:32 pm, dave morgan wrote:
> > hi,
> >
> > I have put the first bit of javascript I have ever used
> > on my website, at www.eclipse.co.uk/morgad/exmplmenu var.js
> > but I having massive trouble getting the links to work
> > when I call the script from other directories
> > (e.g. www.eclipse.co.uk/morgad/aquapics/diary.html )
> >
> > I have got round it for now by hardcoding the
> > www.eclipse.co.uk/morgad/ root into all paths
> > but there has to be a better way than this.

I would think so.

> I don't know if Javascript can deal with relative links. I suspect it is a 
> problem related to being client-side. 

When a (static) web page is served to a browser no changes are made to the HTML 
so if you have used relative links then only the relative part will be passed on. The 
browser knows the URL of the page it is displaying and uses this to create full links. 
You need to remember that the web is basically stateless so each page (HTML + 
headers) is a standalone entity.
Because the browser knows the URL Javascript can access it so you could 
dynamically generate your site root inside the script. Check out some Javascript 
reference site for full details - I think what you need is document.URL but I haven't 
checked.

Cheers,

Pete.


--
The Mailing List for the Devon & Cornwall LUG
Mail majordomo@xxxxxxxxxxxx with "unsubscribe list" in the
message body to unsubscribe.


Lynx friendly