Right click disable

Divinum Fiat

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!
 
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. :-)
 

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();
    });
  });
 
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>
 
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. :)
 
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>
 
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:
 
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>

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

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. :)
 
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!

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. :)
 
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>
 
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.

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. :)
 
Top Bottom