BASE attribute to ignore anchor links

Discussion in 'HTML' started by Dan Fingerman, Mar 4, 2005.

  1. I have a page with the BASE tag:

    <BASE HREF="http://www.server.com/path/page.html">

    This works the way I want for src references and links leading away
    from my page -- they lead to the BASE url. However, I want anchor
    links to go to the anchor name on my page -- not on the BASE page.
    Unfortunately, this happens: The following link on my page:

    <A HREF="#anchor">link</a>

    leads to http://www.server.com/path/page.html#anchor instead of to

    <A NAME="anchor">

    on my page.

    Is there an attribute for the BASE tag that prevents this? Or is
    there some other way to prevent it?

    --
    DTM :<|
    www.danfingerman.com
    Dan Fingerman, Mar 4, 2005
    #1
    1. Advertising

  2. Dan Fingerman wrote:

    > I have a page with the BASE tag:
    >
    > <BASE HREF="http://www.server.com/path/page.html">


    server.com is a real domain. Please use "example.com" which is
    reserved for the purpose.

    Since your anchor links work without the base href, why use it? Links
    to other pages - either within your site or elsewhere - should also
    work without it. I've never been able to find a need for a base href.

    --
    -bts
    -This space intentionally left blank.
    Beauregard T. Shagnasty, Mar 4, 2005
    #2
    1. Advertising

  3. On Fri, 04 Mar 2005 06:50:46 +0000, Dan Fingerman wrote:

    > I have a page with the BASE tag:
    >
    > <BASE HREF="http://www.server.com/path/page.html">
    >
    > This works the way I want for src references and links leading away
    > from my page -- they lead to the BASE url. However, I want anchor
    > links to go to the anchor name on my page -- not on the BASE page.
    > Unfortunately, this happens: The following link on my page:
    >
    > <A HREF="#anchor">link</a>
    >
    > leads to http://www.server.com/path/page.html#anchor instead of to
    >
    > <A NAME="anchor">
    >
    > on my page.
    >
    > Is there an attribute for the BASE tag that prevents this? Or is
    > there some other way to prevent it?


    I believe the solution you are looking for is:
    <base href="http://www.server.com/path/">

    When you specify a file in the base statement, all links are going to try
    to relate to that file. If you specify the path only, then file links
    will relate to the path, however links referring to the current document
    should be fine.

    Carolyn
    Carolyn Marenger, Mar 4, 2005
    #3
  4. Carolyn Marenger <> wrote:

    >> <BASE HREF="http://www.server.com/path/page.html">

    - -
    > I believe the solution you are looking for is:
    > <base href="http://www.server.com/path/">


    It certainly isn't. The two are completely equivalent. If in doubt, check
    the HTML specs. If still in doubt, test it.

    > When you specify a file in the base statement, all links are going to try
    > to relate to that file.


    Where did you get such an idea? Everything after the last "/" character in
    the href attribute of a base element is ignored. People may still put
    something there, since the virtually only sensible use for the construct is
    in testing things, when you have copied a document from somewhere and want
    to make it behave as on the original server. Then you might just as well
    keep the last part of the path (the one that so often gets mapped to a
    filename) as a reminder of the exact origin.

    --
    Yucca, http://www.cs.tut.fi/~jkorpela/
    Pages about Web authoring: http://www.cs.tut.fi/~jkorpela/www.html
    Jukka K. Korpela, Mar 4, 2005
    #4
  5. On Fri, 04 Mar 2005 15:59:47 +0000, Jukka K. Korpela wrote:

    > Carolyn Marenger <> wrote:
    >
    >>> <BASE HREF="http://www.server.com/path/page.html">

    > - -
    >> I believe the solution you are looking for is:
    >> <base href="http://www.server.com/path/">

    >
    > It certainly isn't. The two are completely equivalent. If in doubt, check
    > the HTML specs. If still in doubt, test it.
    >
    >> When you specify a file in the base statement, all links are going to try
    >> to relate to that file.

    >
    > Where did you get such an idea? Everything after the last "/" character in
    > the href attribute of a base element is ignored. People may still put
    > something there, since the virtually only sensible use for the construct is
    > in testing things, when you have copied a document from somewhere and want
    > to make it behave as on the original server. Then you might just as well
    > keep the last part of the path (the one that so often gets mapped to a
    > filename) as a reminder of the exact origin.


    Thank you for the correction.

    Carolyn
    Carolyn Marenger, Mar 4, 2005
    #5
  6. Beauregard T. Shagnasty wrote at Fri 04 Mar 2005 04:45:10, in
    <news:>:

    > Dan Fingerman wrote:
    >
    >> I have a page with the BASE tag:
    >>
    >> <BASE HREF="http://www.server.com/path/page.html">

    >
    > server.com is a real domain. Please use "example.com" which is
    > reserved for the purpose.


    Noted for the future -- thanks for the tip.


    > Since your anchor links work without the base href, why use it?
    > Links to other pages - either within your site or elsewhere -
    > should also work without it. I've never been able to find a need
    > for a base href.


    A group I work with frequently saves web pages from a particular site
    to a local drive and share them via email. All the href and src tags
    and the css references in these pages are relative, not absolute. We
    want the img src tags and links to work properly when we load the
    pages we have stored locally (that is, we want them to reference the
    site from which the page was saved), but we want the anchor tags to
    point to the local page we have saved.

    I thought the easiest way to accomplish this would be to add a base
    tag to the header of each file. However, this makes the anchor links
    also point to the path specified in the base tag, rather than to the
    page saved locally.

    The next easiest way to accomplish what we want seems to be to find
    and replace each occurence of ="/ with ="http://www.example.com/.

    Any other suggestions?

    --
    DTM :<|
    www.danfingerman.com
    Dan Fingerman, Mar 7, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Barry
    Replies:
    1
    Views:
    502
    =?Utf-8?B?U3RldmUgR29vZHllYXI=?=
    May 21, 2005
  2. henry tourneur
    Replies:
    5
    Views:
    4,851
    Steve Pugh
    Dec 23, 2004
  3. AAaron123
    Replies:
    11
    Views:
    1,133
    AAaron123
    Nov 27, 2008
  4. Q
    Replies:
    0
    Views:
    127
  5. Rob Meade
    Replies:
    6
    Views:
    264
    Rob Meade
    Mar 1, 2004
Loading...

Share This Page