SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2013
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question 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.

    Code:
    <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...th-javascript/


    Any Idea?

    -Thanks

  2. #2
    The CSS Clinic is open silver trophybronze trophy
    Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    40,352
    Mentioned
    179 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by edge82 View Post

    Any Idea?
    Yes, just don't do it.

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

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,810
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    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.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  4. #4
    SitePoint Zealot
    Join Date
    Apr 2013
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  5. #5
    Non-Member
    Join Date
    Feb 2012
    Posts
    892
    Mentioned
    10 Post(s)
    Tagged
    0 Thread(s)
    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? 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.

  6. #6
    Non-Member
    Join Date
    Feb 2012
    Posts
    892
    Mentioned
    10 Post(s)
    Tagged
    0 Thread(s)
    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?


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •