Here is the ultimate code block that combines all the above four codes. This does all the following:
- Disables right click context menu
- Disables text selection, copying (Ctrl + C, V)
- Disables viewing page source (Ctrl + U)
- Disables viewing Developer Tools (F 12 and Ctrl + Shift + I key combinations)
//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> |