Hi guys :)

Is there a chance to disable these two things from my site?
(View Source) and (Ctrl + C )

please, give me few minutes from your time and help, i'll be much more appreciated :)


thanks in advance :)

For this I use onKeyDown event. See the following code
that disables CTRL C and CTRL V.

Note that this is not enough to prevent COPY/PASTE
in a text field, since the user can use CTRL INS, SHIFT INS
or simply use the context menu (right click on text field).

<html>
<head>
<script language="javascript">

function onKeyDown() {
  // current pressed key
  var pressedKey = String.fromCharCode(event.keyCode).toLowerCase();

  if (event.ctrlKey && (pressedKey == "c" || 
                        pressedKey == "v")) {
    // disable key press porcessing
    event.returnValue = false;
  }

} // onKeyDown

</script>
</head>

<body>
<form name="aForm">
<input type="text" name="aText" onkeydown = "onKeyDown()">
</form>
</body
</html>

Thanks a lot you did helped me a lot that's nice from you :D

thanks a lot, much appreciated :)

That's awesome :D
never seen before a female programmer :D

that's cool :D

This code to disable ctrl (control).once you disable the ctrl other all event such as ctrl+C,ctrl+A etc. are disable.

<script language='javascript'> //function for to disable ctrl event of the page.
	function document.onkeydown() 
	{ 
		if ( event.keyCode==17) //17 is ascii code for ctrl
		{ 
			event.keyCode = 0; 
			event.cancelBubble = true; 
			return false; 
		} 
	}
</script>

Edited 6 Years Ago by Ezzaral: Added code tags. Please use them to format any code that you post.

This code to disable ctrl (control)

The bad news is that your code is not cross-browser compatible.
Even in IE, it doesn't prevent copying with other keystrokes or with the mouse. It also doesn't deal with <iframe>s [and possibly <frame>s as well, but I didn't bother to test].

The good news is that this thread had been dead for almost two years before you resurrected it, so the prior participants are unlikely to care. Plus, it gives a link to a page which explains in some detail why the 'view source' part of the request [which you didn't address] is not possible.

garyrichard, disable the mouse right click with:

<script>
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;

</script>

In addition to the above example you can also add the below commands into your HTML <body> tag. Which will disable the keyboard and mouse in Internet Explorer.

oncontextmenu="return false" onselectstart="return false" ondragstart="return false"

Just change your tag <body> or <body whatever here> with

<body expr:class='&quot;loading&quot; + data:blog.mobileClass' oncontextmenu='return false;' onkeydown='return false;' onmousedown='return false;' style='-moz-user-select: none;'>

But it's still easy, some people just use view-source:yourUrl, I just need the answer about how to disable view-source:Url or encript our html code, thanks

@Ahmad_10, please create a new post instead of pull a very old post up.

If you want to disable view source from a browser menu, you will have to force open a new window with menubar/toolbar disabled. However, it is still defeated easily if the person really knows how to deal with "javascript." Therefore, there is no permanent way to do so.

You cannot prevent a user from seeing or copying the source code of your web pages. You can do some things to make it difficult for a human to read the code, but they don't really help much. In the end, you have to send valid HTML to the user's browser, and all the user has to do is select "Save" from the File menu and he has your code on his computer where he can do as he pleases with it.

I used these code below to protect my salespage

<!-- a code to show alert to enable javascript --> <div align="center"><noscript> <div style="position:fixed; top:0px; left:0px; z-index:3000; height:100%; width:100%; background-color:#FFFFFF"> <div style="font-family: Arial; font-size: 17px; background-color:#00bbf9; padding: 11pt;">Mohon aktifkan javascript pada browser untuk mengakses halaman ini!</div></div> </noscript></div> <!-- a code to protect from text selection, block text etc --> <script type="text/javascript">
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)}
</script> <!-- a code to protect content from right click --> <script type="text/javascript">
function mousedwn(e){try{if(event.button==2||event.button==3)return false}catch(e){if(e.which==3)return false}}document.oncontextmenu=function(){return false};document.ondragstart=function(){return false};document.onmousedown=mousedwn
</script> <!-- a code to protect shorcut keyboard, view source etc --> <script type="text/javascript">
window.addEventListener("keydown",function(e){if(e.ctrlKey&&(e.which==65||e.which==66||e.which==67||e.which==73||e.which==80||e.which==83||e.which==85||e.which==86)){e.preventDefault()}});document.keypress=function(e){if(e.ctrlKey&&(e.which==65||e.which==66||e.which==67||e.which==73||e.which==80||e.which==83||e.which==85||e.which==86)){}return false}
</script> <!-- a code to protect your articles --> <script type="text/javascript">
document.onkeydown=function(e){e=e||window.event;if(e.keyCode==123||e.keyCode==18){return false}}
</script>

Edited 3 Months Ago by pritaeas: Removed spam link.

This question has already been answered. Start a new discussion instead.