Categorias:

Desativar a seleção de texto com Javascript

Código para desativar a seleção de texto em uma página, com Javascript.

/*
 * disable text selection
 */
function difluirDisableSelection(e) {
    if ( typeof e.onselectstart != "undefined" ) {
        e.onselectstart = function(){ return false };
    } else if ( typeof e.style.MozUserSelect != "undefined" ) {
        e.style.MozUserSelect = "none";
    } else {
        e.onmousedown = function(){ return false }; 
        e.style.cursor = "default";
    }
}

window.onload = function(){
    difluirDisableSelection(document.body);
}