breaking into the unknown…

prevent right click on page : jquery contextmenu

Leave a comment

contextmenu, tell a user of available options with a data element like links , input etc. You have observed a list of options shown to you when you right click on a webpage like : “reload”, “view page source” etc, similarly when you right click a link, it show you options like : “open in new window”, “open in new tab”  etc. These are the examples of contextmenu implemented by browser i,e they are default features of each browser. You can create your own context menu when needed in your application. Say you application is for managing image gallery, then you want, the right click to provide “copy”, “cut”, “save”, “downlaod” etc options on right click of a folder or image. A no of plugin are available there, to write custom contextmenu . some of them are listed below

for people working on Rubu on Rails, gems also available for developing contextmenu

Well, I have not tried any of the above plugin or gems, as my current requirement was not to set contextmenu, but to prevent it. I’ am working on financial domain website, and for security reason they do not want the user to access any contextmenu provided by the browser. So basically they want to disable right click on the page . It can be, achieved by the few lines of code. just put the below lines of code on page , you want to prevent the right click.

<script type=”text/javascript”>
      alert(“For Security Reason Right Click Disabled on This Page”)

Note that contextmenu is a event like click, mouseover , keydown etc. So, to prevent it we have just prevented its default behaviour. complete list of events is available here at the bottom of the page . contextmenu event is explained in detail here .

Author: arunyadav4u

over 7 years experience in web development with Ruby on Rails.Involved in all stage of development lifecycle : requirement gathering, planing, coding, deployment & Knowledge transfer. I can adept to any situation, mixup very easily with people & can be a great friend.

Leave a Reply

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

You are commenting using your 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