Skip to content

Instantly share code, notes, and snippets.

@pbaruns
Last active November 26, 2022 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pbaruns/2803db7a223808e76ccc05e7217ea3d6 to your computer and use it in GitHub Desktop.
Save pbaruns/2803db7a223808e76ccc05e7217ea3d6 to your computer and use it in GitHub Desktop.
Disable the ctrl u keyboard shortcut
// disable viewing page source
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
document.onkeydown = function(e) {
if (e.ctrlKey &&
(e.keyCode === 67 ||
e.keyCode === 86 ||
e.keyCode === 85 ||
e.keyCode === 117)) {
alert('Content is protected\nYou cannot view the page source.');
return false;
} else {
return true;
}
};
$(document).keypress("u",function(e) {
if(e.ctrlKey)
{
return false;
}
else
{
return true;
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment