2016-06-23 4 views
2

I manage several websites that use a featured article scroller on their homepages, which allows the user to click a forward or back arrow in order to see the next article headline and blurb while remaining on the same page.空の要素(<a href="#">) valid for accessibility purposes?

I use WAVE's accessibility checker and any sites that have this particular plugin throw an error back because within the code there is an empty link, written as <a href="#">. Is there any way around this? I've defined a title attribute but the # is causing the empty link error to still come up.

Some places I've seen that this is perfectly acceptable and others claim this is a problem. What's the actual answer and potential workaround?

+2

[潜在的な関連する回答](http://stackoverflow.com/a/19167175/2930477)あなたはhref属性を必要とせず、単に ' Back'/''のようなものを使うことができます。 [この回答も関連しています](http://stackoverflow.com/a/10510353/2930477)。 – misterManSam

+0

私は私の答えにdownvoteを持っている理由は何ですか? – aardrian

答えて

5

Change the <a href="#"> to a <button> and put your event handler on it.

Some more context on which elements belongs where....

Does the Control Take Me to Another Page? Use an Anchor

If, when clicked, tapped, or activated by keyboard or voice (or insert novel interaction method here), the user is whisked to another URL (including an anchor on the same page), then use <a href="[URL]">. Make sure you use the href attribute and that it has a real URL, not a “#” (otherwise you’re probably relying on JavaScript, which is not at all necessary for a hyperlink). If an href points to just a “#”, then you’re probably doing it wrong. If it points to a named anchor as part of your progressive enhancement efforts, then that’s totally valid.

Does the Control Change Something on the Current Page? Use a Button

If, when activated, the user is not moved from the page (or to an anchor within the page), but instead is presented with a new view (message boxes, changes in layout, etc.), then use a <button>. While you could use an<input type="button">, it’s more likely you’ll get into conflicts with pre-existing styles and subsequent developers (like me).

Does the Control Submit Form Fields? Use a Submit

If, when activated, information the user has entered (either by manually typing or by choosing items on the screen) is being sent back to the server, then use an <input type="submit">. This has better live within a <form>. If you need more styling control or have to embed more than just a simple text string, use a <button type="submit"> instead.

Keyboard Considerations

Think of keyboard users for a moment. A hyperlink can be fired by pressing the enter key. But a true button can be fired by pressing the enter key or the space bar. When a hyperlink has focus and the user presses the space bar, the page will scroll one screenful. If there isn’t more to scroll then the user just experiences nothing. Given a set of interface elements that look the same, if some work with a space bar and some don’t, you can’t expect users to have much confidence in how the page behaves.

I think it’s also worth mentioning that events triggered by a space bar only fire when the key is released, whereas using the Enter key will fire the event as soon as you press the key down (prior to releasing it).

+0

すばらしいすべての人に感謝します。そして、アードリアン、私はあなたがなぜ落選したのか分かりません。非常に役立つもの。私は明日それに

+0

スクリプトが特に 'a'を探しているかどうかを確認し、もしあれば、それを確認します(または' button'で置き換えます)。 – aardrian

+0

@ aardrianあなたを落胆させた人々はあなたの答えを読まなかった。聞かないで、良い仕事を続けてください。私はあなたの答えに非常に感謝します。 – Adam

0

Some sourceなど)は、<a href="#">link</a>が無効なハイパーテキスト参照になることを示唆していますが、問題はWCAG 2の範囲外のJavaScript以外のブラウザにのみ存在することになります。WAVEは考えてエラーではありません。

がここでの問題は、あなたがtitle属性を追加すると、WAVEアルゴリズムを満たしていないことを<a href="#"></a>と空のリンクコンテンツを持っているという事実である。

あなたの唯一の懸念がある場合WAVEを満足させるために、リンクにいくつかのコンテンツを入れて、CSSのトリックを使ってこの共同を非表示にするネタント。

+0

アドバイスをいただき、ありがとうございました。href属性を削除することで問題なく動作しました。 :-) – NiamLeeson

+0

@NiamLeesonノートは 'href'属性を削除するので、リンク – Adam

+0

を発表していないスクリーンリーダーとの互換性の問題とにつながる可能性があること、アダムは、あなたが最善の解決策は、スクリーンリーダーを満足させるためにはその前述の

関連する問題