什么决定了 link 是否被访问?

What determines if a link is visited?

我在测试我们的网络应用程序的可访问性时遇到问题,尽管看起来很简单,但我无法在 Google.

上找到明确的答案

问题是屏幕 reader(特别是 iOS 和 OSX Safari 中的画外音)将应用程序中的每个内部 link 读取为 "Visited Link" 甚至在用户点击其中任何一个之前。 link 都具有相同的基数(类似于 http://domain.com/path/index.html#what-the-link-does),所以我的第一直觉是,由于这些 link 都指向同一文件上的不同哈希值,因此 links 被视为已访问,因为该文件已被访问。

但是,这不是我们想要的行为。我们希望所有 link 都被称为 "Link"。所以这是我的问题:

  1. 是什么决定了link是否被认为访问过?只是访问域会导致它吗?访问特定文件会导致它吗?或者同一个文件的不同哈希应该有不同的访问状态?

  2. 有什么方法可以控制这种行为并防止 link 被访问时读取?也许是一些 Aria 参数?

它取决于实现。根据the spec,

It is possible for style sheet authors to abuse the :link and :visited pseudo-classes to determine which sites a user has visited without the user's consent.

UAs may therefore treat all links as unvisited links, or implement other measures to preserve the user's privacy while rendering visited and unvisited links differently.

规范只要求 :link:visited 互斥,但没有指定如何互斥。

我可能误解了这个问题,但是如果你的链接在你的例子中index.html,你能不能不替换

http://domain.com/path/index.html#what-the-link-does

简单地

#what-the-link-does

访问的逻辑可能只查看 URI,而不考虑查询字符串/锚标记

我认为您遇到的问题是锚标记在可访问性方面的误用。我假设您正在编写一个单页应用程序,每个 link 到不同的视图都是一个锚点。你应该使用 button 标签而不是一些 CSS 忍术。这里有一篇关于这件事的精彩文章:

http://www.karlgroves.com/2013/05/14/links-are-not-buttons-neither-are-divs-and-spans/