More than one link shares the same link text error

For general web development questions that are not specifically related to CSS HTML Validator. This includes (but is not limited to) general HTML, CSS, Accessibility, JavaScript, and SEO questions.
Post Reply
c24m48
Rank II - Novice
Posts: 26
Joined: Fri Jun 17, 2005 5:05 pm

More than one link shares the same link text error

Post by c24m48 »

As I get more aggressive in turning on validation options, one of the warnings I get is the following:

If more than one link on a page shares the same link text, then those links should point to the same resource. If two or more links refer to different resources but share the same link text, then specify different values for the "title" attribute of the "a" element to distinguish the links. [P2, 13.1]

In the context of the page I'm working in, having more than one link share the same link text yet not point to the same resource is not only valid but is completely necessary. Following the advice to specify different values for the "title" attribute of the "a" element does not seem to make the warning go away. Any suggestions?
c24m48
Rank II - Novice
Posts: 26
Joined: Fri Jun 17, 2005 5:05 pm

Figured it out, but I think it's a bug anyway (maybe!)

Post by c24m48 »

Let's say there are two links that share the same link text, and that correctly point to different resources. A warning condition is raised, with the second occurrence of the same link text being flagged, not the first. I add a title to the second occurrence because that's the one being flagged. I hit F6, and the warning persists. I find the first occurrence (the one that wasn't flagged), add title to it, and the warning goes away. The warning goes away when a title is added to the first link, even if no title is added to the second link, and even though it is the second link and not the first link that is flagged with a warning.

If I were the author of the program, I'm not sure if I would consider this a bug or not. And even if I did consider it to be a bug, I'm not sure how I would propose to fix it. It's a subtle issue. But it's a manual process to find the first occurence of the duplicate link text because CSE doesn't flag it for me.

The reason I can't change the link text is because it's my genealogical Web site and the link text is a person's given name in old census data. You can certainly have two (or more) people named John or named William and some such, and you can't change the text because that would be changing their name. The "title" trick on the "a" tag is a perfect solution. It's just clumsier than I would prefer to find the first occurence of the duplicate link text. And CSE doesn't know it's duplicate text until it encounters the second occurrence.
User avatar
Lou
Rank V - Professional
Posts: 297
Joined: Fri Jul 29, 2005 5:55 pm
Location: CO
Contact:

Post by Lou »

c24m48 you are correct this is a subtle bug. Its been a while sense I worked on parsers but IMHO to really fix this would require 2 passes through the HTML.

The problem is that on the first (only) top to bottom pass through the HTML there is no reason to flag the first <a> with a warning ("title" not required or recommended). When the parser gets to the second <a> and "knows" there are two similar references it is to late to add a warning for the first <a>. It would require a structural change to the Validator to get a warning to point to 2 lines of code or to go back and add a warning to the first <a>.

Why adding a "title" to the second <a> does not resolve the warning is an other issue. In fact I would say that with 2 similar <a>s on a page BOTH should have a "title" to help "...user agents (visual and non-visual) to tell users about the nature of..." the difference between links to William (Billy) and William (Big Bill) in your example.

It just occurred to me that both <a> references could be to the same William and so the "title" would be the same or superfluous. Which is why it is a warning and not an error. Does putting the same "title" on both <a>s eliminate the warning?
User avatar
Lou
Rank V - Professional
Posts: 297
Joined: Fri Jul 29, 2005 5:55 pm
Location: CO
Contact:

Post by Lou »

c24m48,

I need some more information about your reported warning. What flags settings do you have "on" to get the reported warning?

I finely had some time to try to duplacate the condition and I guess I don't have my settings correct. with all the required stuff between
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd"> and <BODY> and after </BODY> I used the following code:

<A href="./foo.html">
<IMG src="./JPG/foo2.jpg" alt="test words">
</A>

<H2>this is some text</H2>

<A href="./foo.html">
<IMG src="./JPG/foo2.jpg" alt="test words">
</A>

I only get one warning and that is about the link to ICRA.

Now you really have my 'what's up'! Being able to duplacate the situation is an absolute requirement which comes before understanding which must come before a "fix" can be even thought about. So help me duplacate your [P2, 13.1] warning so we can fully document what you found.

Its to hot to get a life

Lou
c24m48
Rank II - Novice
Posts: 26
Joined: Fri Jun 17, 2005 5:05 pm

Recreating the problem

Post by c24m48 »

Something like the following should do it.

<a href="../knox/1860.html#williamsmith">William</a>


<a href="../anderson.1860.html#williamjones">William</a>

In both cases, the link text is "William". But one link is to William Smith in Knox County in 1860, and the other link is to William Jones in Anderson County in 1860.

It is also necessary to enable accessability checking in order to generate the warning.

It is the second link -- the one to William Jones in Anderson County -- that gets the warning message. All my pages say http://www.w3.org/TR/html4/strict.dtd, but I'm not sure if strict.dtd is necessary in order to get the warning.

Jerry Bryan
User avatar
Lou
Rank V - Professional
Posts: 297
Joined: Fri Jul 29, 2005 5:55 pm
Location: CO
Contact:

Post by Lou »

Jerry,

Now I got it. I needed the text not <IMG> to get the warning just like you said :oops: Now I can play

Lou
User avatar
Albert Wiersch
Site Admin
Posts: 3785
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Post by Albert Wiersch »

I've been watching this thread. :-)

Please let me know if you find something that you consider to be a bug. If so, then please be sure to provide sample HTML to reproduce it and feel free to recommend a solution as well.
Albert Wiersch, CSS HTML Validator Developer • Download CSS HTML Validator FREE Trial
User avatar
Lou
Rank V - Professional
Posts: 297
Joined: Fri Jul 29, 2005 5:55 pm
Location: CO
Contact:

More than one link shares the same link text error

Post by Lou »

Albert thinks for the push to share what I have found out.

Jerry identified an interesting issue; When 2 (or more) lines of code result in a warning the first line involved is not identified. The second and following lines each have a warning linked to them.

The following code can be cut-and-pasted into the validator to get the warning Jerry started this thread with.


<P>This code fragment

<A href="foo">illustrates</A>

the warnings received when code is validated with "Options", "Validator Engine Options...", "Enable Accessibility Checking" on.
</P>
<P>Adding different "title" attributes to each "a" element

<A href="foo2">illustrates</A>

the suggested method to distinguish between the links.
</P>
<P>For example, if the link text is the same but resources are

<A title="different hrefs" href="foo3">different</A>

and the title attributes are

<A title="different titles" href="foo4">different</A>

then no warning is generated.
</P>

The Warning -- [Web Content Accessibility Guidelines 1.0 (Priority 2)]

The link text "illustrates" has already been used to link to a different resource (foo). If more than one link on a page shares the same link text, then those links should point to the same resource. If two or more links refer to different resources but share the same link text, then specify different values for the "title" attribute of the "a" element to distinguish the links. [P2, 13.1]

--

The warning(s) highlights the second or following "a" tag(s) but where is the first one? The clues are the resource (foo) or the link text, either of which can be entered into the search tool (Ctrl+F) to find the first "a" tag with the same link text that needs a "title" attribute.

I could not duplicate that the warning can be resolved with only one "title".

To add a warning for the first "a" tag would require a two-pass parser, not a practical resolution IMHO. (There is nothing wrong with the first "a" tag until the second one is reached. By then it is to late to link a warning to the first line of code.)

I suggest:

1) Change the warning to make it clearer that each "a" tag needs a unique "title" attribute: "...then specify different values for the "title" attribute FOR EACH of the "a" elementS USING THE SAME LINK TEXT to distinguish the links. [P2, 13.1]" :idea:

2) Add the line number of the first use of the link text, for example: "...already been used to link to a different resource (foo) (line xx)."
Post Reply