简体   繁体   English

对于508兼容页面上的javascript链接,HREF属性应该是什么?

[英]What should the HREF attribute be for javascript links on a 508 compliant page?

I know this question: Which "href" value should I use for JavaScript links, "#" or "javascript:void(0)"? 我知道这个问题: 我应该为JavaScript链接使用哪个“href”值,“#”或“javascript:void(0)”? contains a discussion of what the correct href content should be for javascript links. 讨论了javascript链接的正确href内容应该是什么。 How does this relate to 508 compliance? 这与508合规性有何关系? Does anyone know if the javascript:void(0) is acceptable when click handlers are defined elsewhere in the javascript code? 当点击处理程序在javascript代码的其他地方定义时,有没有人知道javascript:void(0)是否可以接受?

This is where terminology becomes important - in terms of accessibility there is no such thing as "a javascript link". 这就是术语变得重要的地方 - 在可访问性方面,没有“javascript链接”这样的东西。 There are links, which are unadulterated anchor elements, and there are javascript behaviours, which should be assumed not-runnable for accessibility. 有链接,它们是纯粹的锚元素,并且存在javascript行为,应该假设这些行为不可用于可访问性。

An empty anchor element that triggers javascript (so something like href='#' onclick='...') is not a link, it's a UI element for triggering page behaviour. 触发javascript的空锚元素(所以像href ='#'onclick ='...'这样的东西)不是链接,它是用于触发页面行为的UI元素。 For accessibility, don't abuse the anchor element for this, use a real UI element with the correct ARIA role. 对于辅助功能,请不要滥用锚元素,使用具有正确ARIA角色的真实UI元素。

For a click-through link (which do something like "click anchor" -> "magical JS is called" -> "window.location is changed to some new page") then be aware that you're semanticlaly misrepresenting your content. 对于点击链接(执行类似“点击锚点” - >“魔法JS被称为” - >“window.location更改为某个新页面”),请注意您在语义上歪曲了您的内容。 Even though you're using an anchor element, your use of it is not as a link, since it's not an anchor to another resource. 即使你使用的是锚元素,你对它的使用也不是一个链接,因为它不是另一个资源的锚。 Like in the above case, it's actually a button. 就像在上面的情况一样,它实际上是一个按钮。 The fact that the page location changes at the end does not change this. 页面位置最后更改的事实不会改变这一点。

For true accessibility, you'll have to give up any JavaScript-in-the-middle. 对于真正的可访问性,您将不得不放弃任何JavaScript中间。 But don't worry, that's much less severe than it sounds: the simplest solution is to use rerouting links instead. 但不要担心,这比听起来要严重得多:最简单的解决方案是使用重新路由链接。 If you've ever used google.com or duckduckgo.com, etc. you'll already be familiar with this: rather than link out to the actual URL, link out to the URL proxied over a page-less script. 如果您曾经使用过google.com或duckduckgo.com等,那么您已经熟悉了这一点:而不是链接到实际的URL,链接到通过无页面脚本代理的URL。 You can guarantee that an anchor with the URL " http://our.domain.com/ref=http://the.actual.link.to.visit ", will end up redirecting to the actual site just fine, and you can tack on any desired operation that should take place "when people click" as a server side action when you resolve the redirect. 您可以保证网址为“ http://our.domain.com/ref=http://the.actual.link.to.visit ”的锚点最终会重定向到实际网站,并且您可以解决在解决重定向时“当人们点击”作为服务器端操作时应该进行的任何所需操作。

508 compliance will be hard if you think you rely on JavaScript. 如果您认为依赖JavaScript,508合规将很难。 So for accessibility: actively try not to. 所以对于可访问性:积极尝试不要。 Enrich if you can use it, ensure things still work without it. 丰富,如果你可以使用它,确保没有它仍然可以工作。

I essentially agree with Mike. 我基本上同意迈克的观点。

How does this relate to 508 compliance? 这与508合规性有何关系?

A common misconception about Section 508 is "oh I ran my site with JAWS (or maybe NVDA), and was fine. So I am compliant." 关于508节的一个常见误解是“哦,我用JAWS(或者可能是NVDA)运行我的网站,并且很好。所以我很顺从。” Section 508 is therotically supposed to cover all disabilities not just blindness. 第508条被认为涵盖了所有残疾,而不仅仅是失明。 When you wonder off into heavy JavaScripting, agencies tend to use the "Software applications and operating systems" (1194.21) Standards in addition to "Web-based intranet and internet information and systems" (1194.22) because they talk more about UI elements. 当你想到重型JavaScripting时,代理商倾向于使用“软件应用程序和操作系统”(1194.21)标准以及“基于Web的内部网和互联网信息和系统”(1194.22),因为他们更多地谈论UI元素。 Places like WebAIM, unfortunately deny this. 不幸的是,像WebAIM这样的地方否认了这一点。

So when 1194.21 is included, the Standards can be more easily read as "you put all the @alts and <label> s on, but can this site/app/system with the keyboard? AKA is it keyboard navigatiable?" 因此,当包含1194.21时,标准可以更容易理解为“你把所有@alts和<label>打开,但这个网站/应用程序/系统可以用键盘吗?AKA是键盘可导航的吗?” Can you get to that <span> that looks like a link? 你能看到那个看起来像链接的<span>吗?

As Mke said, one way to assist with this is using ARIA. 正如Mke所说,解决这个问题的一种方法是使用ARIA。 So, that <span> now has to be: 那么, <span>现在必须是:

<span onclick="Clicky()" role="link">Link</span>

(Ref: MDN ) (参考: MDN

Now back to your question: 现在回到你的问题:

I know this question: Href attribute for JavaScript links: "#" or "javascript:void(0)"? 我知道这个问题:JavaScript链接的Href属性:“#”或“javascript:void(0)”? Does anyone know if the javascript:void(0) is acceptable when click handlers are defined elsewhere in the javascript code? 当点击处理程序在javascript代码的其他地方定义时,有没有人知道javascript:void(0)是否可以接受?

I would advocate for the void because when a reference (think it is called an in-page ref)is not defined, the focus goes back to the browser frame, versus staying on the link. 我会提倡虚空,因为当一个引用(认为它被称为页内引用)没有定义时,焦点会回到浏览器框架,而不是留在链接上。 You would need to write some handlers to return the focus to the link. 您需要编写一些处理程序以将焦点返回到链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM