Monday, May 6, 2024
 Popular · Latest · Hot · Upcoming
80
rated 0 times [  86] [ 6]  / answers: 1 / hits: 40651  / 15 Years ago, tue, july 7, 2009, 12:00:00

I am trying to paint cell on a html page, where each cell is a DIV, I need to be able to capture right click event on any of these cells, How can I do that?



<script>
function fn(event)
{
alert('hello'+event.button);
}
</script>

<div id=cell01
class=
onclick=fn(event);
style=left: 1471px; width: 24px; height: 14px; top: 64px; text-align: center; position: absolute; background-color: rgb(128, 128, 0);>1</div>

More From » html

 Answers
82

Take a look at this: Javascript - event properties. Value for right mouse button is 2, although also note that it recommends using mousedown or mouseup events rather than click.



Here is a sample from the page showing right click detection:



function doSomething(e) {
var rightclick;
if (!e) var e = window.event;
if (e.which) rightclick = (e.which == 3);
else if (e.button) rightclick = (e.button == 2);
alert('Rightclick: ' + rightclick); // true or false
}

[#99177] Thursday, July 2, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
stephonkeandrer

Total Points: 392
Total Questions: 94
Total Answers: 100

Location: Tajikistan
Member since Sun, Aug 29, 2021
3 Years ago
;