Disable print screen,CTRL+U for view source using Javascript or JQuery

Hi,

I want to disable print screen and CTRL+U so that users can not see view source.

I am able to disable right click using following.

<script type="text/javascript">
    $(function () {
      $(document).bind("contextmenu",function(e){
        e.preventDefault();
        //alert("Right Click is not allowed");
      }
    );
		/*$('.dvOne').bind("contextmenu",function(e){
		e.preventDefault();
		alert("Right Click is not allowed on div");
		}
		);
		*/
    }
     );
  </script>

Following URL help to disable some keys on keyboard but I am not getting success in disabling CTRL(control) key and print screen.

http://www.heckdesigns.com/tutorials/tutorial-disabling-keyboard-keys-with-javascript/

Any Idea?

-Thanks

Yes, just don’t do it. :slight_smile:

The only solution is not to put anything on the web that you don’t want copied. You can use all the JS you want but users can just view source to get the code or indeed just turn javascript off. Causal users might be fooled (and annoyed to lose their context menu) by the no right clicked but they are not the ones who may want to borrow the code.

See this very old article here and the [URL=“http://www.sitepoint.com/forums/showthread.php?134621-Don-t-Disable-Right-Click!/page5”]millions of comments it generated.

Watermark your images, and add copyright messages to your pages but please don’t disable right click or you will lose a lot of customers. You only have to google a little to see how hated this practice is.

Sorry if that’s not the answer you were hoping for :slight_smile:

You could spend over $200 on a program to “encrypt” your web page but programs to decrypt it again are freely available - they are called web browsers.

If you try to “protect” your content you will always block some legitimate visitors and encourage some thieves who think its clever that they know how to bypass your “protection”. So if you want to decrease legitimate visitors and increase theft then you are on the right track.

Hi felgall and Paul,

Many thanks for your useful information.

I understand that print screen disable will be complicated and not good feel to customers.

Basically when we have online examination web application,copyrigth content document in browser with watermark etc.

These business logic in application need this type of development.

-Thanks

When you develop software, there is always the cost-effective issue for every feature you implement. Implementing source hiding mechanisms in web development is always not worth it AND not working. That is because JavaScript, by nature, has limited control on client side.

Think first of the implications of what you’re thinking you can do to client side. If what you want would be possible without the client side to have anything to say, a lot of other bad things would easily be possible, like illegal remote control and so on.

One other thing to note, very important, is that by pushing the envelope with this type of crappy control attempts on client side, may also result in your site being classified as malware site.

You should just go back to the drawing board and see if you haven’t cut any corners on your deployment system. Relying on JavaScript to protect business logic and intellectual property it’s a dive.

And, you do realize that there are screen recorder apps, that will just put your print screen blocking attempts to shame? What you’re going to do, take control of the client machine and disable screen recording as well? :lol: Your approach screams out loud that this is amateur hour coupled with unrealistic expectations.

In conclusion, get back to the drawing board or live with how things are on the web: users can do whatever they want on their machine, as it should be, and you can’t even control the browser they choose to see your page.

Oh, and I forgot to tell you what users can do to your site. They can use apps like HTTrack WebSite Copier. The name says it all. Have you considered this and its implications on server side? How is that for a surprise?