javascript - document.querySelectorAll('a:visited') doesn't work - Stack Overflow

document.querySelectorAll('a:visited') always returns empty NodeList, even if the DOM has som

document.querySelectorAll('a:visited') always returns empty NodeList, even if the DOM has some visited links.

I have tried it in Chrome. Is there any know bug or is it expected behavior?

While :visited works perfectly fine if I use it in the style sheet instead of querySelectorAll.

a:visited{
    color:yellow;
}

I think pseudo classes are allowed as the parameter of querySelectorAll().

document.querySelectorAll('a:visited') always returns empty NodeList, even if the DOM has some visited links.

I have tried it in Chrome. Is there any know bug or is it expected behavior?

While :visited works perfectly fine if I use it in the style sheet instead of querySelectorAll.

a:visited{
    color:yellow;
}

I think pseudo classes are allowed as the parameter of querySelectorAll().

Share Improve this question edited Apr 16, 2013 at 11:14 BoltClock 725k165 gold badges1.4k silver badges1.4k bronze badges asked Apr 16, 2013 at 6:52 P KP K 10.2k13 gold badges56 silver badges99 bronze badges 2
  • I think it's not possible due to design - otherwise any site would be able to essentially read my history. – Esailija Commented Apr 16, 2013 at 6:59
  • 1 Security reasons. One could simply check whether you visited a website. That's also the reason why you cannot use background-images in :visited anymore, see hacks.mozilla/2010/03/… – Zeta Commented Apr 16, 2013 at 6:59
Add a ment  | 

1 Answer 1

Reset to default 10

I can't find any source citing this behaviour specifically for Chrome, but this sort of thing is usually done to prevent code on the page from being able to access user history, which is a privacy concern.

The Selectors API has a section dedicated to this issue. Here's a small, relevant snippet:

History theft is a potential privacy issue because the :visited pseudo-class in Selectors allows authors to query which links have been visited.
...
As defined in Selectors..., user agents may treat all links as unvisited links.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745077710a4609932.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信