Skip to content

Instantly share code, notes, and snippets.

@lordn-n
Last active January 14, 2018 10:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lordn-n/8010018 to your computer and use it in GitHub Desktop.
Save lordn-n/8010018 to your computer and use it in GitHub Desktop.
Enable/Disable context menu and text selection
/*
* Deshabilita click derecho (menu contextual)
*/
window.oncontextmenu = function(){
return false;
};
/*
* Habilita click derecho (menu contextual)
*/
window.oncontextmenu = function(){
return true;
};
/*
* Deshabilita seleccionar texto
*/
function select_off(){
window.onmousedown = function(){
return false;
};
var elmnts = document.querySelectorAll('*');
for(e = 0; e < elmnts.length; e++){
elmnts[e].style.webkitUserSelect = 'none';
elmnts[e].style.userSelect = 'none';
elmnts[e].unselectable = 'on';
}
}
/*
* Habilita seleccionar texto
*/
function select_on(){
window.onmousedown = function(){
return true;
};
var elmnts = document.querySelectorAll('*');
for(e = 0; e < elmnts.length; e++){
elmnts[e].style.webkitUserSelect = 'auto';
elmnts[e].style.userSelect = 'auto';
elmnts[e].unselectable = '';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment