Solved

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

Posted on 2003-10-21
23
47,691 Views
Last Modified: 2011-08-18
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
Comment
Question by:Jaggee
  • 5
  • 3
  • 3
  • +9
23 Comments
 
LVL 3

Expert Comment

by:applekanna
ID: 9596091
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
 

Author Comment

by:Jaggee
ID: 9596284
Thanks but this wont help in this regard.
0
 
LVL 3

Expert Comment

by:applekanna
ID: 9596442
You cannot disable the ctrl keys in IE .. for more info check this


http://www.questionmark.com/perception/help/v2/securebrowser/psbbusiness.html
0
 
LVL 49

Expert Comment

by:sunray_2003
ID: 9596486
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
 
LVL 49

Expert Comment

by:sunray_2003
ID: 9596525
0
 

Author Comment

by:Jaggee
ID: 9596664
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
 
LVL 49

Accepted Solution

by:
sunray_2003 earned 100 total points
ID: 9596677
0
 
LVL 49

Expert Comment

by:sunray_2003
ID: 9596685
As I said  most likely it wont work if people disable javascript in their browser.. this simply would become ineffective

Sunray
0
 
LVL 49

Expert Comment

by:sunray_2003
ID: 9596689
0
 
LVL 15

Expert Comment

by:VincentPuglia
ID: 9602468
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:Jaggee
ID: 9604609
Sunray,
it works fine.
Thanks for the Help and Ideas.

Vinny
agree with your comments.
0
 
LVL 1

Expert Comment

by:zoobie
ID: 10141481
This reminds me of the thief who calls the cops because he was robbed.
0
 

Expert Comment

by:MCdoublem
ID: 10245761
could enyone tell me how to disable ctrl + c ?????
0
 

Expert Comment

by:caviatte
ID: 10299510
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
 
LVL 15

Expert Comment

by:VincentPuglia
ID: 10299743
Hi caviatte,

And the nail remover:  javascript disabled.

Vinny
0
 

Expert Comment

by:ANMMark
ID: 10924617
and the new hammer <noscript>
0
 

Expert Comment

by:rxd9507
ID: 11300630
Is there anyway that without using client side scripting these functions be achieved?
0
 
LVL 15

Expert Comment

by:VincentPuglia
ID: 11300932
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
 

Expert Comment

by:zahidumar
ID: 11314217
hi,,
I m zahid...i want to creat a control(text box), which only can accept integer value......plz tell me

Thanx.
0
 
LVL 2

Expert Comment

by:Netwing
ID: 11537206
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
 

Expert Comment

by:s_kukutla
ID: 13326543
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

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When you work with shopping cart / ecommerce relates web sites, you need to pass the certain form post details to the payment gateway process page with required details for the products items you give to order. Also you may need to track the ordered…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now