Is there any way to find the co-ordinates of a right click event on a div element as I have to set context menu based on the position of click.
Any help and suggestion will be appreciated. Thanks.
Is there any way to find the co-ordinates of a right click event on a div element as I have to set context menu based on the position of click.
Any help and suggestion will be appreciated. Thanks.
You can try:
$('div').on('contextmenu', function (e) {
console.log(e.pageX);
console.log(e.pageY);
});
And for whole page:
$('div').on('contextmenu', function (e) {
console.log(e.clientX);
console.log(e.clientY);
});
$(document).ready(function(){
document.oncontextmenu = function() {return false;};
$(document).on('mousedown', '#TargetElementId', function (e){
if( e.button == 2 ) { // Right mouse button clicked
return {e.pageX, e.pageY} //return co-ordinates
}
return true;
});
});
From SO Answer to find right mouse button clicked