Skip to content

Instantly share code, notes, and snippets.

@jack2jm
Last active February 12, 2024 05:53
Show Gist options
  • Select an option

  • Save jack2jm/5b54ef1dcc7c60ecbd51e86607cfb663 to your computer and use it in GitHub Desktop.

Select an option

Save jack2jm/5b54ef1dcc7c60ecbd51e86607cfb663 to your computer and use it in GitHub Desktop.
This gist can help you to prevent from view page source using ctrl + u. also this helps you to disable right click.
<script type="text/javascript">
// To To Disable ctrl+c, ctrl+u
jQuery(document).ready(function($){
document.oncontextmenu = document.body.oncontextmenu = function() {return false;}
$(document).keydown(function(event) {
var pressedKey = String.fromCharCode(event.keyCode).toLowerCase();
console.log(pressedKey);
// i, c, j -> open inspect element view
// ctr + u or c -> pag src
// f12 - 123
if ( event.which === 123 || (event.ctrlKey && (pressedKey == "c" || pressedKey == "u")) || (event.ctrlKey && event.shiftKey && (pressedKey == "i" || pressedKey == "c" || pressedKey == "j") ) ) {
//alert('Sorry, This Functionality Has Been Disabled!');
//disable key press porcessing
return false;
}
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment