Why did browsers limit :visited selector?(为什么浏览器会限制 :visited 选择器?)
问题描述
我了解隐私问题,但在 这篇文章 Mozilla 声明他们对 querySelector()
和 getComputedStyle()
撒谎.
I understand the privacy concerns, but in this article Mozilla states that they are lying to querySelector()
and getComputedStyle()
.
如果他们已经在对网站撒谎,那么为什么要将 :visited
限制为简单的颜色?不能使用相同的方法对网站隐藏完整的样式吗?
If they are already lying to sites, than why limit :visited
to just simple colors? Couldn't full styling still be hidden from sites using the same method?
推荐答案
限制可以应用于访问链接的样式,防止它们以可以通过 getComputedStyle() 查询的方式影响不相关元素的布局
——如果不秘密计算整个页面的布局,就无法进行欺骗,就好像所有链接都未访问一样,这在性能方面将是极其昂贵的.这与 :visited + span
之类的东西不再被应用(甚至 :visited
中仍然允许的属性)是一样的.
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
).
考虑一下这个概念验证,您可以在其中单击一个链接来切换模拟其访问性的类名,并查看如何在 :link
和 :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
这篇关于为什么浏览器会限制 :visited 选择器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么浏览器会限制 :visited 选择器?


- 400或500级别的HTTP响应 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- 失败的 Canvas 360 jquery 插件 2022-01-01