Limiting the styles that can be applied to visited links prevents them from affecting the layout of unrelated elements in a way that can be queried by getComputedStyle()
— something that cannot be spoofed without secretly computing the layout of the entire page as if all links were unvisited, which would be extremely expensive performance-wise. This is in the same vein as things like :visited + span
no longer being applied (not even the properties still allowed in :visited
).
Consider this proof-of-concept, in which you can click a link to toggle a class name that simulates its visitedness, and see how toggling between :link
and :visited
can affect layout:
var a = document.querySelector('a'),
p = document.querySelector('p + p');
a.addEventListener('click', function(e) {
a.className = a.className == 'unvisited' ? 'visited' : 'unvisited';
console.log('a is now ' + a.className + '; top pos of following p is now ' + p.getBoundingClientRect().top);
}, false);
a.unvisited {
font-size: 1em;
}
a.visited {
font-size: 2em; /* A property not normally allowed on :visited */
}
<p><a class="unvisited" href="#">Toggle visitedness</a>
<p>Another paragraph
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…