How to disable Right Click on your web page


In this post, we will see how we can disable right click option using simple JQuery code. I hope you will like it.

Background

Most of the developers are always looking for the safety of their images and code blocks which they have shared in the web. But normally it is hard to secure this unless you go for any third party tool. Some of us may think if we just disable the right click option in our page, makes the content secured. But it is not. If some one really thinks that they need to get the content from your page, they can achieve it. Even though that is the reality, I am sharing this post to show how to disable the right click option in page.

Code

We are going to use JQuery for this requirement. So you need to load the JQuery reference first.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>


Now we need to add the needful script.

$(document).ready(function() {
     $(document).on("contextmenu",function(e){
         return false;
     }); 
});

Here what we did is, whenever user tries to perform right click in the document, we are restricting that. We are applying this restriction to the entire document. And we use contextmenu event to do this requirement.

That is all. Everything is done and set. Now you need to see the output and demo right?

Demo

You can see a demo here Disable Right Click Demo

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s