954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to Disable (View Source) and (Ctrl+C) from a site?

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 :)

Q8iEnG
Junior Poster
171 posts since Jun 2008
Reputation Points: 10
Solved Threads: 2
 
Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
 

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>
Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
 

how to disable ctrl+c:
http://www.faqs.org/faqs/msdos-programmer-faq/part2/section-16.html

And
That shortcut is handled by the operating system. It never reaches the browser and so the browser has no opportunity to pass it to the web page.

IE only:

Add the following code to your BODY tag:

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

Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
 

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

thanks a lot, much appreciated :)

Q8iEnG
Junior Poster
171 posts since Jun 2008
Reputation Points: 10
Solved Threads: 2
 

Fine....

Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
 

As long you do not provide pure HTML site nothing is as it seems in source view...

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

Shanti Chepuru

u done good work

nikesh.yadav
Posting Whiz in Training
219 posts since Feb 2008
Reputation Points: 15
Solved Threads: 21
 

Yeah, he did :)

Q8iEnG
Junior Poster
171 posts since Jun 2008
Reputation Points: 10
Solved Threads: 2
 

thanks for ur compliments...
Yeah, he did :)
And im female....

Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
 

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

that's cool :D

Q8iEnG
Junior Poster
171 posts since Jun 2008
Reputation Points: 10
Solved Threads: 2
 

thank you...

Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
 

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>
kirtikadm
Newbie Poster
1 post since Jun 2010
Reputation Points: 10
Solved Threads: 0
 
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 s [and possibly 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.

fxm
Posting Pro
596 posts since Apr 2010
Reputation Points: 40
Solved Threads: 74
 

no no no dont use this code on blogger because this code remove your blogger account i tryed


[IMG]http://gyazo.com/a6509f73adedc42878187980872eb780.png[/IMG]:sad::@:icon_cry:

tahirhayatkhan
Newbie Poster
1 post since Sep 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You