How to enable right click context menu?

Posted on April 28, 2008 
Filed Under Tips and tricks

These days we see a lot of websites which have disabled right click for so called security reasons. I am using Mozilla Firefox and have spell check installed. I was writing an email to my bank’s branch manager and wanted to correct a misspelled word but when I right clicked the incorrect word to see the suggestion. I got a message in a browser alert:

Due to security reasons, Right click is not allowed

It can really be a big pain if someone wants to paste a message or a transaction number or correct a misspelled word like in my case. So I figured out a work around. Lets see how the right click is disabled at the first place:

<script> 
    document.oncontextmenu=function(){
        // Add alert or notification
        return false; // Cancel the event chain
    } 
</script>

The piece of code above will block the context menu event with a custom function that is usually used to give an alert like I got on my Bank’s website. And false value is returned so that the event chain is stopped and context menu is not displayed.

Now to enable the context menu again we will have to remove this method that is blocking the context menu functionality of a web page. For this we can reassign the context menu event with a null value or we can assign a method that returns a true value so that the event chain is not blocked or stopped or interrupted.

We can also use javascript protocol of our browsers to add the javascript to enable right click to our bookmarks or enable right click via address bar. Here is how we can do this:

javascript:void(document.oncontextmenu=null)

Click here to "disable" right click context menu on this page

Click here to "enable" back the right click context menu on this page

Comments

Leave a Reply