• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 48623
  • Last Modified:

How do i Disable Ctrl+C,Ctrl+V,Ctrl+P,Ctrl+N,Alt+PrintScreen keys ?

i would like to protect Copy&Paste  and Print functions in a web application.
How do i disable  Ctrl+C,Ctrl+V,Ctrl+P,Ctrl+N and Alt+PrintScreen keys.
i am using win2k and IE browser.
Can anyone help me out?
0
Jaggee
Asked:
Jaggee
  • 5
  • 3
  • 3
  • +9
1 Solution
 
applekannaCommented:
TO disable right click on theimages add the following code from the thread
http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_20703460.html

<SCRIPT LANGUAGE="JavaScript1.1">
<!-- Begin
function right(e) {
if (navigator.appName == 'Netscape' &&
(e.which == 3 || e.which == 2))
return false;
else if (navigator.appName == 'Microsoft Internet Explorer' &&
(event.button == 2 || event.button == 3)) {
alert("Right click disabled.");
return false;
}
return true;
}
document.onmousedown=right;
if (document.layers) window.captureEvents(Event.MOUSEDOWN);
window.onmousedown=right;
//  End -->
</SCRIPT>


does this help?
Cheers!
0
 
JaggeeAuthor Commented:
Thanks but this wont help in this regard.
0
 
applekannaCommented:
You cannot disable the ctrl keys in IE .. for more info check this


http://www.questionmark.com/perception/help/v2/securebrowser/psbbusiness.html
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
sunray_2003Commented:
Jaggee,

As applekanna has said it is not possible to disable functions like that ..

Whatever you do there are ways to trick and people can copy the contents from your html file. lot of questions similar to this has been answered in EE and people were convinced that it cannot be. One of the reasons is generally people use javascripts and other scripting which the user can easily disable so that it will not work

Sunray
0
 
sunray_2003Commented:
0
 
JaggeeAuthor Commented:
my problem is not Disabling the view- source ,but to disable the Print Screen function,
Here is a sample code ,
 from this code ,I can able to disable Alt+PrintScreen ,Copy & Paste but when i use Ctrl+P to Print the page ,it prints the page.
So how do i disable Ctrl + P ?
any help?

------ Sample Code ---------
<html>
<head>
<script language="Javascript">
function setClipBoardData(){
      setInterval("window.clipboardData.setData('text','')",20);
}
function blockError(){
      window.location.reload(true);
      return true;
}
window.onerror = blockError;
</script>
</head>
<body onload="setClipBoardData();">
<center>
<h1>Print Screen test</h1>
</center>
</body>
</html>
0
 
sunray_2003Commented:
0
 
sunray_2003Commented:
As I said  most likely it wont work if people disable javascript in their browser.. this simply would become ineffective

Sunray
0
 
sunray_2003Commented:
0
 
VincentPugliaCommented:
Hi,

  Why are you even trying to disable the print function?  I can visit your site, download it, and then print at my leisure.  If you are trying to protect text and code -- forget it -- the best you can do is copyright.  If you are trying to protect images -- the best you can do is copyright & watermark.  

  If you have another reason for disabling the print function, you should state it -- there may be an alternative.  If you are simply trying to protect something from surfers -- don't waste your time and ours -- it is not possible.

Vinny
0
 
JaggeeAuthor Commented:
Sunray,
it works fine.
Thanks for the Help and Ideas.

Vinny
agree with your comments.
0
 
zoobieCommented:
This reminds me of the thief who calls the cops because he was robbed.
0
 
MCdoublemCommented:
could enyone tell me how to disable ctrl + c ?????
0
 
caviatteCommented:
This nails just about EVERYTHING.  MSIE, Netscape, Opera, Mozilla, on PC and Mac.
NO right click.
NO print screen key.
No Ctrl + C
No Highlighting anything with the mouse.
All print functions (Ctrl+P, Print Icon, File>>Print) deliver a BLANK PAGE.

Note: The alerts for rightclicks are in unicode.

Here Goes :

<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
<!--
hp_ok=true;
function hp_d00(s)
{
  if(!hp_ok)return;
  document.write(s)
}
//-->
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
<!--
function hp_ne()
{
  return true
}
onerror=hp_ne;
function hp_dn(a)
{
  return false
}
function hp_cm()
{
  alert("\u0054\u0068\u0069\u0073\u0020\u0070\u0061\u0067\u0065\u0020\u0068\u0061\u0073\u0020\u0062\u0065\u0065\u006E\u0020\u0070\u0072\u006F\u0074\u0065\u0063\u0074\u0065\u0064\u002E\u0020\u0050\u0072\u0065\u0076\u0069\u0065\u0077\u0020\u006F\u006E\u006C\u0079\u002E");
  return false
}
function hp_de(e)
{
  return(e.target.tagName!=null&&e.target.tagName.search('^(INPUT|TEXTAREA|BUTTON|SELECT)$')!=-1)
};
function hp_md(e)
{
  mac=navigator.userAgent.indexOf('Mac')!=-1;
  if(document.all)
  {
    if(event.button==2||(mac&&(event.ctrlKey||event.keyCode==91)))
    {
      alert("\u0054\u0068\u0069\u0073\u0020\u0070\u0061\u0067\u0065\u0020\u0068\u0061\u0073\u0020\u0062\u0065\u0065\u006E\u0020\u0070\u0072\u006F\u0074\u0065\u0063\u0074\u0065\u0064\u002E\u0020\u0050\u0072\u0065\u0076\u0069\u0065\u0077\u0020\u006F\u006E\u006C\u0079\u002E");
      return(false)
    }
  }
  else
  {
    if(e.which==3||(mac&&(e.modifiers==2||e.ctrlKey)))
    {
      alert("\u0054\u0068\u0069\u0073\u0020\u0070\u0061\u0067\u0065\u0020\u0068\u0061\u0073\u0020\u0062\u0065\u0065\u006E\u0020\u0070\u0072\u006F\u0074\u0065\u0063\u0074\u0065\u0064\u002E\u0020\u0050\u0072\u0065\u0076\u0069\u0065\u0077\u0020\u006F\u006E\u006C\u0079\u002E");
      return false
    }
    else if(e.which==1)
    {
      window.captureEvents(Event.MOUSEMOVE);
      window.onmousemove=hp_dn
    }
  }
}
function hp_mu(e)
{
  if(e.which==1)
  {
    window.releaseEvents(Event.MOUSEMOVE);
    window.onmousemove=null
  }
}
if(navigator.appName.indexOf('Internet Explorer')==-1||(navigator.userAgent.indexOf('MSIE')!=-1&&document.all.length!=0))
{
  if(document.all)
  {
    mac=navigator.userAgent.indexOf('Mac')!=-1;
    version=parseFloat('0'+navigator.userAgent.substr(navigator.userAgent.indexOf('MSIE')+5),10);
    if(!mac&&version>4)
    {
      document.oncontextmenu=hp_cm
    }
    else
    {
      document.onmousedown=hp_md;
      document.onkeydown=hp_md;
    }
    document.onselectstart=hp_dn
  }
  else if(document.layers)
  {
    window.captureEvents(Event.MOUSEDOWN|Event.modifiers|Event.KEYDOWN|Event.MOUSEUP);
    window.onmousedown=hp_md;window.onkeydown=hp_md;
    window.onmouseup=hp_mu
  }
  else if(document.getElementById&&!document.all)
  {
    document.oncontextmenu=hp_cm;document.onmousedown=hp_de
  }
}
function hp_dp1()
{
  for(i=0;i<document.all.length;i++)
  {
    if(document.all[i].style.visibility!="hidden")
    {
      document.all[i].style.visibility="hidden";document.all[i].id="hp_id"
    }
  }
};
function hp_dp2()
{
  for(i=0;i<document.all.length;i++)
  {
    if(document.all[i].id=="hp_id")document.all[i].style.visibility=""
  }
};
window.onbeforeprint=hp_dp1;
window.onafterprint=hp_dp2;
document.write('<style type="text/css" media="print"><!--body{display:none}--></style>');
function hp_dc()
{
  hp_ta.createTextRange().execCommand("Copy");
  setTimeout("hp_dc()",300)
}
if(navigator.appName.indexOf('Internet Explorer')==-1||(navigator.userAgent.indexOf('MSIE')!=-1&&document.all.length!=0))
{
  if(document.all&&navigator.userAgent.indexOf('Opera')==-1)
  {
    document.write('<div style="position:absolute;left:-1000px;top:-1000px"><input type="textarea" name="hp_ta" value=" " style="visibility:hidden"></div>');
    hp_dc()
  }
}
function hp_ndd()
{
  return false
}
document.ondragstart=hp_ndd;
//-->
</SCRIPT>
</head>
<body>
<center>
<h1>Print Screen test</h1>
</center>
</body>
</html>
0
 
VincentPugliaCommented:
Hi caviatte,

And the nail remover:  javascript disabled.

Vinny
0
 
ANMMarkCommented:
and the new hammer <noscript>
0
 
rxd9507Commented:
Is there anyway that without using client side scripting these functions be achieved?
0
 
VincentPugliaCommented:
HI rxd9507,

  I think the majority of coders would say: You cannot prevent a determined individual from taking your stuff as his/her own.  Using server-side scripting means the actual source code is protected from the casual surfer, but that's it.  

  The last word:  why bother?  you haven't and will not create anything that hasn't already been created and re-created umpteen million times on the web.

Vinny
0
 
zahidumarCommented:
hi,,
I m zahid...i want to creat a control(text box), which only can accept integer value......plz tell me

Thanx.
0
 
NetwingCommented:
Try this:

<head>
<script language="javascript">
<!--
function clearData(){
window.clipboardData.setData('text','')
}
function deldat(){
if(clipboardData){
clipboardData.clearData();
}
}
setInterval("deldat();", 1000);
//-->
</script>

</head>


<body onload="deldat();">
test
</body>
</html>
0
 
s_kukutlaCommented:
We can disable any key on key board on IE see the code below:

<script language="JavaScript">
function keyWhat(e){
   if (navigator.appName == 'Microsoft Internet Explorer'){
                 //For shift, ctrl and alt keys
      if(event.keyCode == 16 ||event.keyCode == 17 ||event.keyCode == 18 ){
            alert("You Can't use ctrl,shift or alt keys on page");
                      return false;
                 }
   }
}//end of function
document.onkeydown=keyWhat;
</script>
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 5
  • 3
  • 3
  • +9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now