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

I figured as much, but always need to state the obvious just for the record so there is no illusion for anyone else who may stumble of this thread with the same question ;)
 
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>

This worked great, thank you!!!
 
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.

Good to know this exist, Adam. Thank you for posting!

My forum members are definitely not in the technical category to go through this much length to override this little hurdle. Yes, they can always hire someone to bypass this function but why go through the trouble. This will cut down on the number of things copied easily. I will watch tynt over the next 2 days and tell you how many less copies that have been made as a result of this.

Thank you all - so appreciate you!
 
Yay, it worked. This morning, the only pages copied were the ones I tested yesterday for this widget. Thank you!!

Does this widget also work for Wordpress sites?

If you are talking about my code then it will work in any web page which uses jQuery (or similar libraries). If jQuery is not included then there are two ways to fix it. Either rewrite the code to remove dependency of jQuery (as it was in the first post that only blocks context menu.) or include jQuery in the page. :)
 
Thank you both. I tried but didn't get it to work.

I can also recommend tynt.com, which is what's giving me the stats for the XF site. I just found some great little tools in there where they will actually create backlinks to your site and add social networking stuff, etc.
 
Last edited:
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>


where I need to add this code in the theme?
 
I did, but it did not work

<script>

<xen:hook name="page_container_js_body">
jQuery.extend(true, XenForo,
{
visitor: { user_id: {$visitor.user_id} },
serverTimeInfo:
{
now: {$serverTimeInfo.now},
today: {$serverTimeInfo.today},
todayDow: {$serverTimeInfo.todayDow}
},
_lightBoxUniversal: "{$xenOptions.lightBoxUniversal}",
_enableOverlays: "@enableOverlays",
_animationSpeedMultiplier: "@animationSpeedMultiplier",
_overlayConfig:
{
top: "@overlayTop",
speed: {xen:calc '@overlaySpeed * @animationSpeedMultiplier'},
closeSpeed: {xen:calc '@overlayCloseSpeed * @animationSpeedMultiplier'},
mask:
{
color: "@overlayMaskColor",
opacity: "@overlayMaskOpacity",
loadSpeed: {xen:calc '@overlaySpeed * @animationSpeedMultiplier'},
closeSpeed: {xen:calc '@overlayCloseSpeed * @animationSpeedMultiplier'}
}
},
_ignoredUsers: {xen:helper json, $visitor.ignoredUsers},
_loadedScripts: {/*<!--XenForo_Required_Scripts-->*/},
_cookieConfig: { path: "{xen:jsescape $xenOptions.cookieConfig.path}", domain: "{xen:jsescape $xenOptions.cookieConfig.domain}", prefix: "{xen:jsescape $xenOptions.cookieConfig.prefix}"},
_csrfToken: "{xen:jsescape $visitor.csrf_token_page}",
_csrfRefreshUrl: "{xen:jsescape {xen:link login/csrf-token-refresh}}",
_jsVersion: "{$xenOptions.jsVersion}"
});
jQuery.extend(XenForo.phrases,
{
cancel: "{xen:jsescape {xen:phrase cancel}}",

a_moment_ago: "{xen:jsescape {xen:phrase a_moment_ago}}",
one_minute_ago: "{xen:jsescape {xen:phrase one_minute_ago}}",
x_minutes_ago: "{xen:jsescape {xen:phrase x_minutes_ago, 'minutes=%minutes%'}}",
today_at_x: "{xen:jsescape {xen:phrase today_at_x, 'time=%time%'}}",
yesterday_at_x: "{xen:jsescape {xen:phrase yesterday_at_x, 'time=%time%'}}",
day_x_at_time_y: "{xen:jsescape {xen:phrase day_x_at_time_y, 'day=%day%', 'time=%time%'}}",

day0: "{xen:jsescape {xen:phrase day_sunday}}",
day1: "{xen:jsescape {xen:phrase day_monday}}",
day2: "{xen:jsescape {xen:phrase day_tuesday}}",
day3: "{xen:jsescape {xen:phrase day_wednesday}}",
day4: "{xen:jsescape {xen:phrase day_thursday}}",
day5: "{xen:jsescape {xen:phrase day_friday}}",
day6: "{xen:jsescape {xen:phrase day_saturday}}",

_months: "{xen:jsescape '{xen:phrase month_1},{xen:phrase month_2},{xen:phrase month_3},{xen:phrase month_4},{xen:phrase month_5},{xen:phrase month_6},{xen:phrase month_7},{xen:phrase month_8},{xen:phrase month_9},{xen:phrase month_10},{xen:phrase month_11},{xen:phrase month_12}'}",
_daysShort: "{xen:jsescape '{xen:phrase day_sunday_short},{xen:phrase day_monday_short},{xen:phrase day_tuesday_short},{xen:phrase day_wednesday_short},{xen:phrase day_thursday_short},{xen:phrase day_friday_short},{xen:phrase day_saturday_short}'}",

following_error_occurred: "{xen:jsescape {xen:phrase following_error_occurred}}",
server_did_not_respond_in_time_try_again: "{xen:jsescape {xen:phrase server_did_not_respond_in_time_try_again}}",
logging_in: "{xen:jsescape {xen:phrase logging_in}}",
click_image_show_full_size_version: "{xen:jsescape {xen:phrase click_image_show_full_size_version}}",
show_hidden_content_by_x: "{xen:jsescape {xen:phrase show_hidden_content_by_x}}"
});

<script type="text/javascript">
<!--
// Disabling context menu, copy, and paste
$(document).ready(function () {
$('body').bind('contextmenu copy paste', function (e) {
e.preventDefault();
});
});
// -->
</script>



// Facebook Javascript SDK
XenForo.Facebook.appId = "{xen:jsescape $xenOptions.facebookAppId}";
XenForo.Facebook.forceInit = {xen:if $facebookSdk, true, false};
</xen:hook>
</script>
 
Last edited:
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>
where to paste this code in ?
 
Top Bottom