-1

I disabled right click and print option (ctrl+P ) and view source (ctrl+U) using javascript. Because of these restrictions keys U and P are not working.Please give me the solution or any alternative way to disable (ctrl+P and ctrl+U)option.

And here is my javascript code:
for print

if(cc.which == 85)  
{  
return false;  
}  
if(cc.which == 80)  
{  
return false;  
}

for right click

status="Right Click Disabled";  
function disableclick(event)  
{  
if(event.button==2)  
{  
alert(status);  
return false;    
}  
}
Keerthi K
  • 1
  • 5
  • Do you want to disable right click only because you want to disable printing option? If not, then this might help : http://stackoverflow.com/questions/16006583/capturing-ctrlz-key-combination-in-javascript – Hari Harker Aug 03 '16 at 07:03
  • thank you for your suggestion.. I want to disable right click to hide my source code.plz give me solution – Keerthi K Aug 03 '16 at 09:11

2 Answers2

1

You can't prevent the user from printing, but you can hide everything when the user prints the document by using simple CSS:

<style type="text/css" media="print"> * { display: none; }</style>
Hudhaifa Yoosuf
  • 869
  • 2
  • 12
  • 28
0

You can't prevent the user from printing, but you can hide everything when the user prints the document by using simple CSS:

<style type="text/css" media="print">
    * { display: none; }
</style>

refer : How to disable printing options in the browser for certain pages

How to Disable the CTRL+P using javascript or Jquery?

Community
  • 1
  • 1
Sanjeev kumar
  • 60
  • 1
  • 3