Results 1 to 6 of 6

Thread: (X)HTML: base tag

  1. #1

    Thread Starter
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    (X)HTML: base tag

    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
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  2. #2
    Fanatic Member davebat's Avatar
    Join Date
    Dec 2002
    Posts
    727
    what does the base tag do

  3. #3

    Thread Starter
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    The base tag sets the URL to which all relative URLs in the page relates.

    Example
    Code:
    <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:
    Code:
    /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.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4
    Fanatic Member twanvl's Avatar
    Join Date
    Dec 2001
    Posts
    771
    According to the HTML spec:
    This attribute specifies an absolute URI that acts as the base URI for resolving relative URIs.
    (emphasis mine)

    xml:base 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.

  5. #5

    Thread Starter
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  6. #6
    Fanatic Member twanvl's Avatar
    Join Date
    Dec 2001
    Posts
    771
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width