使用JavaScript或Dart确定浏览器的默认文本突出显示颜色 [英] Determine browser's default text highlight color using JavaScript or Dart
问题描述
浏览器的默认文字高亮(选择)背景颜色可以覆盖,例如:
The browser's default text highlight (selection) background color can be overridden, e.g.:
::selection {
background: #ffb7b7;
}
并且颜色是特定于浏览器/操作系统的。有没有办法读取浏览器的默认值使用JavaScript或Dart?
And the color is browser/OS specific. Is there a way to read the browser's default value using JavaScript or Dart?
推荐答案
我会说,你不能。
两个 getComputedStyle(yourElement,':: selection')。backgroundColor
和 getComputedStyle yourElement,':: - moz-selection')。backgroundColor
将返回 transparent
作为默认值,浏览器不会覆盖os的默认值。 >
(值得提及,如果你将其设置为透明,默认os'值将被覆盖)。
Both getComputedStyle(yourElement, '::selection').backgroundColor
and getComputedStyle(yourElement, '::-moz-selection').backgroundColor
will return transparent
as default value and browser won't override os's default.
(Worth to be mentioned that if you set it to transparent, default os' value will be overriden).
我不认为浏览器可以访问os默认偏好,如果他们这样做,他们可能不会让任何网站访问它这么容易。
I don't think browsers have access to os default preferences, and if they do, they probably won't let any website access it it so easily.
这篇关于使用JavaScript或Dart确定浏览器的默认文本突出显示颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!