How to Disable source code and Right click mouse?

812 views Asked by At

Which script is used in this website ? We cannot View Source code (Ctrl+U) and Right click mouse. I want to add like this script to my site. Could you please provide the script.

2

There are 2 answers

1
Nishant Saini On

var isCtrl = false;
document.onkeyup=function(e)
{
    if(e.which == 17)
    isCtrl=false;
}
document.onkeydown=function(e)
{
    if(e.which == 17)
    isCtrl=true;
    if((e.which == 85) || (e.which == 67) && (isCtrl == true))
    {
        return false;
    }
}
var isNS = (navigator.appName == "Netscape") ? 1 : 0;
if(navigator.appName == "Netscape") document.captureEvents(Event.MOUSEDOWN||Event.MOUSEUP);
function mischandler(){
    return false;
}
function mousehandler(e){
    var myevent = (isNS) ? e : event;
    var eventbutton = (isNS) ? myevent.which : myevent.button;
    if((eventbutton==2)||(eventbutton==3)) return false;
}
document.oncontextmenu = mischandler;
document.onmousedown = mousehandler;
document.onmouseup = mousehandler;
  

0
mike510a On

That page uses the following code:

 document.oncontextmenu = function(e) {
   var t = e || window.event;
   var n = t.target || t.srcElement;
   if (n.nodeName != "A") return false
 };
 document.ondragstart = function() {
   return false
 };


 function disableSelection(e) {
   if (typeof e.onselectstart != "undefined") e.onselectstart = function() {
     return false
   };
   else if (typeof e.style.MozUserSelect != "undefined") e.style.MozUserSelect = "none";
   else e.onmousedown = function() {
     return false
   };
   e.style.cursor = "default"
 }
 window.onload = function() {
   disableSelection(document.body)
 }
<div style="height: 150; width: 150">
  <a href="link1.html">link 1</a>
</div>

By the way, you cannot protect Javascript source code from being stolen or viewed, as the person visiting the page must be able to view the script in order to run it.