Thursday, January 7, 2016

CSS unselectable text

Came across a strange requirement... some text on the webpage should not be selectable, as in some EULA text. Ok this is stupid. Alt-Printscreen? Take out phone and take screenshot? You just can't protect your text. Also view-source too.

But CSS let you do this. Found a stackoverflow link that shows how. Try below:

<style>
.noselect {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}
 </style>

Selectable text.

Unselectable text. I have class="noselect"

No comments: