0

I have an element with text in it and in between text there are span elements. When I highlight the parts of the text with the span elements in it, it shows those elements text. I looked for a solution and found the following css values, these should disable highlight and by the look of it, it does, but in code the values are still there.

-webkit-touch-callout: none; /* iOS Safari */
-webkit-user-select: none; /* Safari */
 -khtml-user-select: none; /* Konqueror HTML */
   -moz-user-select: none; /* Old versions of Firefox */
    -ms-user-select: none; /* Internet Explorer/Edge */
     -o-user-select: none;
        user-select: none; /* Non-prefixed version, currently
                              supported by Chrome, Edge, Opera and Firefox */

In code I am getting the highlighted text like this window.getSelection().toString().

I cant find any other way to disable highlighting and dont understand why these css values dont work. What am I doing wrong? What other ways are there to disable highlight?

5
  • You can try using canvas to render the text. Commented Oct 28, 2020 at 10:33
  • are you using this on many elements ?? Commented Oct 28, 2020 at 10:33
  • check this stackoverflow.com/questions/1224433/… Commented Oct 28, 2020 at 10:34
  • @AdamAzad Could you write an answer? Commented Oct 28, 2020 at 11:01
  • @AlaaKaddour yes, that seems to answer for firefox. I need this on all browsers Commented Oct 28, 2020 at 11:01

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.