1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Right click disable

Discussion in 'XenForo Questions and Support' started by Core Freedom, Jun 17, 2013.

  1. Core Freedom

    Core Freedom Well-Known Member

    Hi all,

    There is an archived thread here about disabling right-click, but unfortunately the script is only for guests. I need to have right-click disabled even for members.

    I know many disagree with this tactic but given topics and confidentiality of our forums this is a must (most of our visitors also would have not clue how to disabled this function). I've installed a script through Tynt to see how many pages are being copied (and which ones) and it's amazing at what's being "taken."

    The script I have now is this. Can anyone tell me which part I need to change so that right-click is disabled for everyone?

    Code:
    <xen:if is="!{$visitor.user_id}">
    <script type="text/javascript">
    <!--
    
    //Disable right mouse click Script
    //By Maximus (maximus@nsimail.com) w/ mods by DynamicDrive
    //For full source code, visit http://www.dynamicdrive.com
    var message="Right click is disabled for guests!";
    ///////////////////////////////////
    function clickIE4(){
    if (event.button==2){
    alert(message);
    return false;
    }
    }
    function clickNS4(e){
    if (document.layers||document.getElementById&&!document.all){
    if (e.which==2||e.which==3){
    alert(message);
    return false;
    }
    }
    }
    if (document.layers){
    document.captureEvents(Event.MOUSEDOWN);
    document.onmousedown=clickNS4;
    }
    else if (document.all&&!document.getElementById){
    document.onmousedown=clickIE4;
    }
    document.oncontextmenu=new Function("alert(message);return false")
    // -->
    </script>
    </xen:if>
    Thank you!
     
  2. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Remove the first and last lines:

    Code:
    <xen:if is="!{$visitor.user_id}">
    
    ...
    
    </xen:if>
    
    Disabling right click is only a minor inconvenience for some one wanting to copy your content.
     
    Core Freedom likes this.
  3. Core Freedom

    Core Freedom Well-Known Member

    Yes, that worked. I thought I had tried that before and then it let me copy everything again. Thank you, Jake!

    I know it's annoying especially to those who use right click to copy and paste as a habit (or short cuts). Unfortunately I've been watching what's been copied and even though we have the terms and conditions that asks them not to do so, it's obviously not working. And given that we have so much confidential stuff on our site, I feel as the board owner I need to do my part just to protect my members' content. I have no control over those who go around this script, but perhaps it's protecting some of the content. :)

    I actually wish I could find out even if someone tried to go around it by getting a list of IP addresses from those who take content and then where they post it. I get quite protective when it get to things like these. :)
     
  4. James

    James Well-Known Member

    Bare in mind there's also ctrl + c which is used to copy data.
     
    Core Freedom likes this.
  5. Core Freedom

    Core Freedom Well-Known Member

    Darned, I thought it would include ctrl + c. Anyway to include disabling that as well?
     
  6. ibnesayeed

    ibnesayeed Well-Known Member

    Possible! :)
     
    Core Freedom likes this.
  7. CyclingTribe

    CyclingTribe Well-Known Member

    You can often use the "View Source" option in your browser to copy content too (sorry, but that's another way people can get around a disabled right-click).
     
    Core Freedom likes this.
  8. James

    James Well-Known Member

    Bare in mind there are other methods, such as screenshotting, disabling JS, viewing source.

    I hope this works for your users, though.
     
    Core Freedom likes this.
  9. Core Freedom

    Core Freedom Well-Known Member

    Pretty cool, thank you!

    My challenge. I don't read code. The code they list seems to come in 3 parts. The first one apparently doesn't work for firefox. Now that I have the code above installed, do I install this INSTEAD or in ADDITION TO?

    Would anyone mind telling me where these extra 2 pieces go?

    Here is part 1:

    Code:
    <html>
    <head>
    <script language="javascript">
    
    function Disable_Control_C() {
    var keystroke = String.fromCharCode(event.keyCode).toLowerCase();
    if (event.ctrlKey && (keystroke == 'c' || keystroke == 'v')) {
    alert("let's see");
    event.returnValue = false; // disable Ctrl+C
    }
    }
    </script>
    </head>
    <body onkeydown="javascript:Disable_Control_C()">
    Hello World!
    </body>
    </html>
    
    Not sure about the "Hello world" piece.

    Part 2:

    Code:
    <body oncopy="return false" oncut="return false" onpaste="return false">
    Part 3:

    Code:
    $(document).ready(function () {
        $('#Selector').bind('copy paste', function (e) {
          e.preventDefault();
        });
      });
     
  10. ibnesayeed

    ibnesayeed Well-Known Member

    You don't need the whole thing really. There are many suggestions to do the same thing. Below is the necessary code injected in to earlier code. I didn't test it so take it with a pinch of salt. :)

    Code:
    <script type="text/javascript">
    <!--
    
    // Disabling copy/paste
    $(document).ready(function () {
        $('body').bind('copy paste', function (e) {
           e.preventDefault();
        });
    });
    
    //Disable right mouse click Script
    //By Maximus (maximus@nsimail.com) w/ mods by DynamicDrive
    //For full source code, visit http://www.dynamicdrive.com
    var message="Right click is disabled for guests!";
    ///////////////////////////////////
    function clickIE4(){
    if (event.button==2){
    alert(message);
    return false;
    }
    }
    function clickNS4(e){
    if (document.layers||document.getElementById&&!document.all){
    if (e.which==2||e.which==3){
    alert(message);
    return false;
    }
    }
    }
    if (document.layers){
    document.captureEvents(Event.MOUSEDOWN);
    document.onmousedown=clickNS4;
    }
    else if (document.all&&!document.getElementById){
    document.onmousedown=clickIE4;
    }
    document.oncontextmenu=new Function("alert(message);return false")
    // -->
    </script>
     
    Core Freedom likes this.
  11. ibnesayeed

    ibnesayeed Well-Known Member

    In fact this whole thing can be lot simpler because you are already using jQuery as part of XF that simplifies this whole junk of code. Let me see if I can further slim the code. :)
     
  12. ibnesayeed

    ibnesayeed Well-Known Member

    Try this code and it should take care of everything including right click menu and copy/paste. :)
    Code:
    <script type="text/javascript">
    <!--
    // Disabling context menu, copy, and paste
    $(document).ready(function () {
      $('body').bind('contextmenu copy paste', function (e) {
        e.preventDefault();
      });
    });
    // -->
    </script>
     
    Core Freedom likes this.
  13. Core Freedom

    Core Freedom Well-Known Member

    You absolutely rock, ibnesayeed! Thank you! It works on both the IE and FF. My short cuts (ctrl + c) are broken online, not sure why (they work in Word but not when I browse, so couldn't test it there.

    Thank you, thank you! :notworthy:
     
    ibnesayeed likes this.
  14. Core Freedom

    Core Freedom Well-Known Member

    Should I use this? I don't see where I can customize the message though. It worked with the code above, except I don't know if the short cut works. When I try ctrl + c nothing happens, no message, and I'm not able to use ctrl + v either (some configuration in my laptop is off).

    Thank you again. You're so amazing!
     
  15. ibnesayeed

    ibnesayeed Well-Known Member

    I am glad that I was helpful. By the way if you only want to prevent COPY you don't really need to prevent PASTE functionality. And I think you have pretty good idea what to do to enable pasting. :)
     
    Core Freedom likes this.
  16. Core Freedom

    Core Freedom Well-Known Member

    it's a duh moment for me. :confused:

    Thank you!
     
  17. ibnesayeed

    ibnesayeed Well-Known Member

    This is the shortest version I could come up with. And if you are using this, you don't need the earlier code you had in your first post. It takes care of all that. Although I did not throw annoying alerts. If you want to let users know that they cant do this then I will adjust the code to show an alert. :)
     
    Core Freedom likes this.
  18. ibnesayeed

    ibnesayeed Well-Known Member

    This version of code will only disable context menu (menu on right click) and copy. It will allow users to paste content in the forum that they copied from somewhere else. It will also show an alert on right click and Ctrl+C. :)
    Code:
    <script type="text/javascript">
    <!--
    // Disabling context menu and copy
    $(document).ready(function () {
      $('body').bind('contextmenu copy', function (e) {
        alert('We encourage you not to COPY content from here and honor our Terms and Conditions!');
        e.preventDefault();
      });
    });
    // -->
    </script>
     
    Core Freedom likes this.
  19. Adam Howard

    Adam Howard Well-Known Member

    It is impossible to keep someone from right clicking and doing a copy & paste. There is even a firefox add-on that helps people overcome scripts like this. It's called, "right to click"

    https://addons.mozilla.org/firefox/addon/righttoclick/

    This is only 1 of a hundred ways I can think of which make it possible.
     
    Core Freedom likes this.
  20. ibnesayeed

    ibnesayeed Well-Known Member

    I guess she is aware of that fact but if her forum is not full of geeks, she will probably only find one out of hundred members going that far. And there are good guys whom if you remind to honor copyright, they will. :)
     

Share This Page