“跳过导航”链接在 Google Chrome 中不起作用
我按照此页面创建“跳过导航”链接,但它在 Chrome (5.0.0) 中不起作用。 375.127)。
当我按 Tab 键并输入链接时,它会滚动到内容,但是当我继续按 Tab 键时,它会从顶部开始,而不是从内容开始。
该页面的跳过“跳过导航”链接在 Chrome 中也不起作用。
这是Chrome的一个bug吗?有什么解决办法吗?
I follow this page to make a "Skip Navigation" link, however it is not working in Chrome (5.0.375.127).
When I tab and enter the link, it scroll to the content, but when I continue to tab, it starts from the top but not start from the content.
That page's skip "Skip Navigation" link is not working in Chrome either.
Is it a bug of Chrome? Any workaround?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我可以确认Andy Li的答案有效,但我不需要scrollTo的东西。我还添加了一个钩子,这样如果您正在加载已应用锚链接的页面,则会给出适当的焦点。
我的版本是:
I can confirm that Andy Li's answer works, but I didn't need the scrollTo stuff. I also added in a hook so that if you are loading a page with an anchor link already applied, the appropriate focus would be given.
My version was:
Chrome (Webkit) 中存在一个已知错误,该错误会阻止您两次滚动到某个锚点。
因此,如果您之前打开#anchor,向上滚动,然后再次单击指向#anchor 的链接,则它将不起作用。
请参阅:http://code.google.com/p/chromium/ issues/detail?id=42511
我还没有尝试过,但是先使用 javascript 清除哈希怎么样?
像这样:
在 Chrome 中测试了以下内容,它有效:
There is a known bug in Chrome (Webkit) that prevents you from scrolling twice to an anchor.
So if you openen #anchor previously, scrolled up, and clicked again on a link reffering to #anchor, it won't work.
See: http://code.google.com/p/chromium/issues/detail?id=42511
I haven't tried it yet, but what about using javascript to clear the hash first?
Like this:
Tested the following in Chrome, it works:
我得到它。目标应该是一个可以聚焦的标签,比如链接,如果不是,我的例子是一个div,应该将目标的tabindex设置为-1。
我的 jQuery 解决方案(使用 ScrollTo 插件)是:
I get it. The target should be a tag that can be focused, like a link, if not, which is my case a div, should set tabindex of the target as -1.
My jQuery solution, with ScrollTo plug-in, is:
我认为将此归因于 chrome bug #37221 按照 Knu 的答案 跳过在 Chrome 中不起作用的链接。
我不同意 Javascript 解决方法适合长期使用。
I believe it is most correct to attribute this to chrome bug #37221 as per Knu in the answer to Skip links not working in Chrome.
I don't agree that Javascript workarounds are appropriate for the long term.
我知道这是一个老问题,但经过几个小时的搜索后,我今天终于偶然发现了它。我仍然没有找到解决这个问题的非 js 解决方案,尽管该问题在 Chrome 中被标记为已修复,但它仍然表现出相同的行为。由于缺乏其他东西,我使用了 jQuery。我没有使用内联脚本,而是使用了一个不显眼的事件侦听器。
HTML:
jQuery:
我还隐藏链接,除非它从键盘接收焦点。这样,只有键盘用户和屏幕阅读器才会知道该链接的存在。使用CSS3,您可以确保当用户快速点击它时它会短暂可见。
CSS:
要进行演示,您可以查看 fiddle。如果有人有关于使用 javascript 的方法,我很想听听。我认为如果需要js,解决方案就不是真正可以访问的。
I know this is an old question, but I finally stumbled across it today after searching for hours. I still haven't found a non-js solution to this, and though the issue is marked as fixed in Chrome, it still exhibits the same behavior. For a lack of anything else, I used jQuery. Rather than an inline script, I used an unobtrusive event listener.
The HTML:
The jQuery:
I also hide the link unless it receives focus from the keyboard. That way only keyboard users and screen readers will ever know the link is there. Using CSS3, you can ensure that it becomes briefly visible if a user tabs rapidly past it.
The CSS:
For a demonstration, you can view the fiddle. If anyone has a way around the use of javascript, I would love to hear it. I don't think a solution is truly accessible if it requires js.
这是我的解决方法。
它允许键盘跳过导航链接到其页面上的任何元素 ID。
链接的
onclick
事件处理程序位于此处。以下是我的假设。
href
属性的链接才能成为键盘导航锚链接的正确目标。
a
链接中删除href
属性,浏览器仍然会记住键盘导航的焦点位置,而不会在屏幕上显示任何焦点标记更多的。我编写它是为了弹出页面跳过导航,该导航不太可能滚动。
我希望它甚至适用于屏幕阅读器。
Here is my workaround.
It enables keyboard skip navigation link to any element id on its page.
The link's
onclick
event handler is here.The following is my assumption.
a
link withhref
attribute could be the proper destination of anchor link for keyboard navigation.href
attribute froma
link with focus, browsers will still remember the focus position for keyboard navigation while it will not show you the focus mark on the screen any more.I wrote it for popup page skip navigation which isn't likely to be scrolled.
I hope it will works even for screen readers.
这是没有 jQuery 的相同解决方案。
添加页面锚点:
链接到内容:
我的 jsfiddle
Here's the same solution without jQuery.
Add page anchor:
Link to the content:
My jsfiddle