How to Prevent Right Click in Joomla?

Many of our customers ask us to disable right click on their Joomla website. As such, we have decided to write a post explaining how this is done.

Before starting, you need to be aware of the following:

  • Preventing right clicks will only deter non-technical visitors from stealing your content (such as text and images). Right click prevention can be easily overcome by simply disabling JavaScript in the browser settings.
  • Preventing right clicks will not affect your search engine rankings, and search engines will still index your website normally (search engines tend to ignore JavaScript code on your website, unless, of course, it’s malicious).

  • Even if the person has not disabled JavaScript, he will still be able to copy content from your website by simply selecting the text and then clicking on CTRL+C.

Now that you know that preventing right clicks is not an efficient way to protect your content, let us explain to you how you can do it.

The first thing you need to do is to copy the following code:


<SCRIPT TYPE="text/javascript">

<!--
var msg = "Right click disabled"; //change this message to a message of your own if you want
var showMsg = 1; //change this to 0 if you do not want to show any popup messages when the user right clicks

function internetExplorerRightClick(){ //code to handle right clicks in Internet Explorer
if (document.all){
if (showMsg == 1){
alert(msg);
}
return false;
}
}

function firefoxRightClick(e){ //code to handle right clicks in Firefox and Chrome (as well as other obsolete browsers such as Netscape)
if ((document.layers) || (document.getElementById && !document.all)) {
if (e.which==2 || e.which==3){
if (showMsg == 1){
alert(msg);
}
return false;
}
}
}

if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=firefoxRightClick;
}
else{
document.onmouseup=firefoxRightClick;
document.oncontextmenu=internetExplorerRightClick;
}

document.oncontextmenu=new Function("return false");

// -->
</SCRIPT>

The next thing you need to is to open your Joomla template for editing and place (paste) the above code within the <head> HTML tag. Here’s how you do this:

  • Login to your Joomla website as Super Administrator
  • Click on Extensions, and then click on Template Manager
  • Click on the name of the default template (the template that has a yellow star next to it)
  • Click on Edit HTML on the top right
  • Paste the code above just after the <head> HTML tag
  • Click on Save on the top right
  • That’s it!

Now if you don’t want to display any messages when the user right clicks on your website, then all you need to do is change the value of showMsg to 1.

If you need any help doing the above, then all you need to do is to Contact us. We are very friendly, and we’re always there to help!

One Response to “How to Prevent Right Click in Joomla?”

  1. Pingback by How to Protect Your Content on Your Joomla Website | itoctopus — January 25, 2012 @ 4:34 pm

    [...] right-clicking: You can disable right clicking on your Joomla website by adding some JavaScript code either in your main template or in a Jumi module that is available [...]

Leave a comment