BASE attribute to ignore anchor links

D

Dan Fingerman

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?
 
B

Beauregard T. Shagnasty

Dan said:
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.
 
C

Carolyn Marenger

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
 
J

Jukka K. Korpela

Carolyn Marenger said:
- -
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.
 
C

Carolyn Marenger

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


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
 
D

Dan Fingerman

Beauregard T. Shagnasty wrote at Fri 04 Mar 2005 04:45:10, in
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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top