Stop selected HTML text

part of my page requires a double click, which has an undesirable effect, which sometimes the user inadvertently selects part of the text on the page.

It’s just untidy, but is there a neat way to stop this other than using images instead of text?

thank

+5
source share
3 answers

Here css disables text selection. How to disable text selection highlighting using CSS?

-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-o-user-select: none;
user-select: none;
+11
source

As @arunes suggested, you can do this using CSS for most browsers. However, I read that this does not work with IE 6-8 (at least). For this, you might need something like:

document.getElementById("divDoubleClick").onselectstart = function() { return false; };
+2
source

css

body, div
{
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: -moz-none;
    -ms-user-select: none;
    -o-user-select: none;
    user-select: none;
}

,

input, textarea, .userselecton
{
    -webkit-touch-callout: text;
    -webkit-user-select: text;
    -khtml-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    -o-user-select: text;
    user-select: text;
}

-moz-none, , .

IE

<script type="text/javascript">
    window.addEvent( "domready", function()
    {
        document.addEvent( "selectstart", function(e)
        {
            if ( (e.target.tagName == "INPUT") ||
             (e.target.tagName == "TEXTAREA") ||
                 (e.target.hasClass("userselecton")))
            {
                return true;
            }
            return false;
        } );
    } );
</script>

This not only prevents the selection of background text, but also allows you to select input fields and the element in which you put the userseleton class.

+2
source

All Articles