2

I'm working on an HTML page for a client, this page contains a table with multiple line like this:

<div id="content">
    <div class="line">toto</div>
    <div class="line">titi</div>
    ...
</div>

and my client wants on a click in a line to select this line, well quite simple but he wants a specific color depending on system.

On Windows, it is simple because you only have one color for selecting text (that i'm aware of) but on Mac, you can modify this color in your settings, you can make it green, red or yellow instead of the usual blue.

So with CSS or Javascript (i use JQuery), can i get this color ?

Bonus Question : if the user change this color in his settings, can something tell me this so that i can update my CSS ?

Eudz
  • 540
  • 6
  • 19
Meph
  • 280
  • 3
  • 9
  • 2
    Both Macs and PCs allow you to set your own color scheme. JavaScript does not have access to that. And, just imagine the security nightmares if it could. – Scott Marcus Oct 17 '19 at 13:57
  • https://codepen.io/Gonzalo2683/pen/RWbwEM – Paco Gómez Capón Oct 17 '19 at 14:06
  • Instead of trying to get the colour and apply it (which you can do with the deprecated CS value `highlight` as indicated in the duplicate suggestion by AKX), you could natively select the line using the Selection API. – Touffy Oct 17 '19 at 14:26

2 Answers2

1

Unfortunately you can't get the specific color value of the highlight selection when it's the OS's default in CSS, but you are totally free to change it as you wants.

A workaround could be highlighting programmatically the text on the desired div, which would be, by default, the color defined by the system.

If you think this would be a satisfactory solution, take a look here to see some code sample.

Matheus Gomes
  • 434
  • 2
  • 11
0

I imagine that is imposible because the Operational System allow the user change the color pallet under your preferences. The browser may not access this kind of information.

I hope i am wrong, but for now, i understand that is imposible.

OR

You could configure an specific CSS file for each operational system and it will be prefixed, so you can get the Operational System iformation and select the css file.