-1

I found so many questions about this topic
and there were so many valid working answers using CSS
but I would like a javascript solution and preferably using jQuery
am trying this code to baby step it and debug the issue:

$(document).ready(function() {
  $('body').mousedown(function(e) {
    if (e.which == 3)
      alert('test')
  })
})

I tried this just to see if it works, and I got the alert
so, up to this point all is good.
later on I try to change alert('test') with e.preventDefault() or with return false;
and it doesn't work anymore
where is the problem, and why ?
am on chrome latest update until the moment of writing this if needed to know.

  • 2
    Describe "doesn't work" - what do you expect it to do? – tymeJV Sep 04 '14 at 18:37
  • by the time the event bubbles up to body, its likely that the event already triggered. You'll need to set it on the specific element you don't want click to work on.... – Rooster Sep 04 '14 at 19:01
  • 1
    You gave no context of what was supposed to happen...I'm not sure if you're right clicking or left clicking, if you want to prevent a native action or an event. When you say doesnt work, it helps to say what happens vs what you expect to happen. Dont take down voting so personally, it's designed to help. If you came up to me at my job and said this doesn't work, I would say my exact first comment, what did you expect it to do. – tymeJV Sep 04 '14 at 19:02
  • @tymeJV i think that the title of my question was really so much self-descriptive, "Disable" mouse click ? –  Sep 04 '14 at 19:13
  • And I would ask, left or right mouse? It's all in the details. I'm just trying to help for future questions. – tymeJV Sep 04 '14 at 19:14

2 Answers2

1

i found this method .contextmenu()
and this change worked:

$(document).ready(function() {
  $('body').mousedown(function(e) {
    return false;
  })
})
0

I feel this is what you want to achieve -

<body oncontextmenu="return false">
...hello
</body>
Biswajit Maji
  • 869
  • 13
  • 23