最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Links do not receive the focus when clicked on Chrome - Stack Overflow

programmeradmin3浏览0评论

I came across a very strange behaviour on Chrome which seems like a bug to me: when you click a link, the link does not receive the focus. Worse, the body takes the focus instead.

This behaviour can be observed here: / (see code sample here)

Is this a bug? Is this standard behaviour? Is there any workaround to make the links receive the focus on mouse down, like on the other browsers?

I came across a very strange behaviour on Chrome which seems like a bug to me: when you click a link, the link does not receive the focus. Worse, the body takes the focus instead.

This behaviour can be observed here: http://jsfiddle/YfbR7/4/ (see code sample here)

Is this a bug? Is this standard behaviour? Is there any workaround to make the links receive the focus on mouse down, like on the other browsers?

Share Improve this question asked Aug 23, 2013 at 9:47 Gyum FoxGyum Fox 3,6272 gold badges46 silver badges76 bronze badges 1
  • The same behaviour also applies to checkboxes, see question here: stackoverflow./questions/18400190/… – Gyum Fox Commented Aug 23, 2013 at 10:11
Add a ment  | 

3 Answers 3

Reset to default 7

Add tab index to anchor tag it should work, it's not a bug its a web kit thingy.

<a href="#" tabindex="1">Click me</a>

A link should always natively receive focus. If your link does not have a href attribute it won't (not sure the use case of a link without a href though!).

In addition to the accepted answer:

Since setting tabindex to 1 would change the TAB behavior, I remend setting it to -1 instead: it won't break the TAB navigation and will still enable it from being focused.

<a href="#" tabindex="-1">Example</a>

By the way, here's a very nice article regarding these concerns.


Note: the same thing happened with me, but just on Safari: probably Chrome has already that issue fixed.

发布评论

评论列表(0)

  1. 暂无评论