PDA

Click to See Complete Forum and Search --> : (X)HTML: base tag


CornedBee
Jul 30th, 2003, 12:02 PM
I want to use the <base> tag for my links. Unfortunatly browsers don't seem to accept relative URLs in the href attribute:
<base href="../" />
I don't want to specify an absolute URL as the page will not always be in the same location. Any way to accomplish the effect with a relative URL?

Thanks in advance

davebat
Aug 5th, 2003, 08:30 AM
what does the base tag do

CornedBee
Aug 5th, 2003, 10:36 AM
The base tag sets the URL to which all relative URLs in the page relates.

Example

<html>
<head>
<base href="http://www.vbforums.com/" />
<link rel="stylesheet" type="text/css" href="styles/someone.css" charset="UTF-8" />
...

Would make the stylesheet be
http://www.vbforums.com/styles/someone.css
no matter where the page is located.

What I want is to set a relative URL so that in a directory tree like this:

/webroot/subdir
/webroot/subdir/styles
/webroot/subdir/styles/tutorial
/webroot/subdir/tutorial


that I can reference the stylesheet in styles like
styles/basic.css
no matter where in the directory the html file actually resides, just by adjusting the base tag.
Here are the problems:
1) I can't place the whole thing in the webroot. There is always one or more subdirs which might even change name.
2) The files are now on my local server, but I will later upload them somewhere else.

Because of 1 I cannot use
/styles/basic.css
and because of 2 I cannot use an absolute URL for the href in the base tag.

twanvl
Aug 5th, 2003, 11:52 AM
According to the HTML spec (http://www.w3.org/TR/html401/struct/links.html#edef-BASE):

This attribute specifies an absolute URI that acts as the base URI for resolving relative URIs.

(emphasis mine)

xml:base (http://www.w3.org/TR/xmlbase/) doesn't seem to have such a restriction, but xml-base probably only works with XLink...

I think your best option is to use an absolute base url, and simply replace-in-all-files when you move the site. Or, you just have to type ../ every time.

CornedBee
Aug 6th, 2003, 01:16 AM
xml:base either only works with xlink or xinclude or it is simply not supported by Moz.

I knew about that bit of the spec, I'm looking for some alternative.

twanvl
Aug 6th, 2003, 08:59 AM
I don't think there is another alternative.
The only other thing I can think of is an xsl stylesheet that adds ../ to all relative urls.