Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

document.querySelectorAll('a:visited') doesn't work

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().

like image 765
P K Avatar asked Apr 16 '13 06:04

P K


1 Answers

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.

like image 63
James Allardice Avatar answered Sep 21 '22 01:09

James Allardice