Skip to content

Instantly share code, notes, and snippets.

@pbaruns
Created April 27, 2020 10:46
Show Gist options
  • Save pbaruns/855dfd2dbb511b6da21b316a77093543 to your computer and use it in GitHub Desktop.
Save pbaruns/855dfd2dbb511b6da21b316a77093543 to your computer and use it in GitHub Desktop.
disables 4things: rightClick, textSelection, viewingPageSource, viewingDevTools
//disable Text Selection and Copying
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src='demo-to-prevent-copy-paste-on-blogger_files/googleapis.js'>
</script>
<script type='text/javascript'>
if (typeof document.onselectstart!="undefined" ) {
document.onselectstart=new Function ("return false" );
}
else {
document.onmousedown=new Function ("return false" );
document.onmouseup=new Function ("return true" );
}
</script>
//==========================================================
//disable right click menu
<script>
function blockOne() {
if (document.all) {
return false;
}
}
function blockTwo(e) {
if (document.layers||(document.getElementById&&!document.all))
{
if (e.which==2||e.which==3) {
return false;
}
}
}
if (document.layers){
document.captureEvents(Event.mousedown);
document.onmousedown=blockTwo;
}
else {
document.onmouseup=blockTwo;
document.oncontextmenu=blockOne;
}
document.oncontextmenu=new Function("return false");
</script>
//==============================================================
// disable viewing page source
<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;
}
});
//=============================================================
//disable F12 Key and Ctrl + shift + I combination
$(document).keydown(function (event) {
if (event.keyCode == 123) { // Prevent F12
alert('Content is protected\nYou cannot view the Dev Tools.');
return false;
} else if (event.ctrlKey && event.shiftKey && event.keyCode == 73) { // Prevent Ctrl+Shift+I
alert('Content is protected\nYou cannot view the Dev Tools.');
return false;
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment