Define default browser highlight color using JavaScript or Dart

The default background color for highlighting (selecting) the default browser can be overridden , for example:

::selection { background: #ffb7b7; } 

And the color depends on the browser / OS . Is there a way to read the default value for a browser using JavaScript or Dart?

+5
source share
2 answers

I would say that you cannot.

Both getComputedStyle(yourElement, '::selection').backgroundColor and getComputedStyle(yourElement, '::-moz-selection').backgroundColor returns transparent as the default value, and the browser will not override the os default value.
(It is worth noting that if you set transparency, the default os' value will be overridden).

I don’t think browsers have access to the os default settings, and if they do, they probably won’t allow any website to access it that easily.

+4
source

As described in fooobar.com/questions/1220696 / ... , you can use CSS system colors: https://www.w3.org/TR/2010/PR-css3-color-20101028/#css2-system , though they are out of date, they really work.

+1
source

All Articles