-1

I use autocomplete in JQuery. When it is right-clicked, it shows the data in the autocomplete same as it is left-clicked. How can I disable right click on it? I mean when I right click it, it does not do anything.

Pajri Aprilio
  • 322
  • 5
  • 16

4 Answers4

0

Probably the most reliable thing is to do it for elements rather than annoying people who right click on things :)

    <div oncontextmenu="return false">

    </div>

But that being said, if you are using the jQuery ui autocomplete, right click does not actually fire the right click so you might look into that!

David
  • 5,897
  • 3
  • 24
  • 43
0

Not really sure I understand your question. But maybe like this-

<input id="myInput" onclick="maybeStopAutocomplete()" onblur="enableAutocomplete()"/>

js -

function maybeStopAutocomplete(evt) {
  if(evt.which === 3) {
    myInput.setAttribute("autocomplete", "false");
  }
}

function enableAutocomplete() {
  myInput.setAttribute("autocomplete", "true");
}

yah?

micah
  • 7,596
  • 10
  • 49
  • 90
0

So using the jqueryui docs for autocomplete and another question from SO you get this fiddle which doesn't seem to even register right-clicks nor middle-clicks. So... yay?

Le html:

<input id='box' type='text'>

The javascript:

$(function() {
    var $input = $('#box');
    var availableTags = [
      "ActionScript",
      "AppleScript",
      "PHP",
      "Python",
      "Ruby",
      "Scala",
      "Scheme"
    ];
    $input.autocomplete({
      source: availableTags
      ,select: function(event, ui) {
         var origin = event.originalEvent.originalEvent;
          return false;
          if(origin.type == 'click') {
            switch(origin.which) {
                case 1: // left. here for show
                    break;
                case 2: // middle
                case 3: // right
                    return false;
                    break;
            }
          }
      }
    });
});

including jquery 1.10.2 and jqueryui 1.10.2 to get the fiddle to work

Community
  • 1
  • 1
0

Maybe this is what you want. Try this

<script language="javascript">
document.onmousedown=disableclick;
status="Right Click Disabled";
Function disableclick(e)
{
  if(event.button==2)
   {
     alert(status);
     return false;  
   }
}
</script>

But in this solution if you click the right click it displays the message “Right click disabled”.

If we want to remove the messegebox then this solution do not work.

I am having another simple solution to achieve the same result and also it does not show the messegebox.

In this method we set the oncontextmenu="return false" in the body part of the page so body part will look like

<body oncontextmenu="return false">
...
</body>

So whenever user clicks the right mouse button nothing will happen, no message no context menu.

Sometimes there might be requirement to disable the right click on specific control to achive this we have to follow these steps. 1. remove added code in body (i.e. oncontextmenu=”return false”) 2. Add one table and in its row add the control e.g. datagrid control 3. put the oncontextmenu=”return false” in the for that control

So code will look like this

<Body>
  <Table>
   <tr oncontextmenu="return false">
    <td>
     <asp:datagrid id="dgGrid1">---</asp:datagrid>

So by this method context menu on the right click of right mouse click can be disabled.

I hope it helps.

Micaela
  • 132
  • 13