How do I simulate a rightclick on the html element

N

Napoleon

Hey all,

I am looking for a way to trigger a Right Click on any HTML element
using javascript. I got a way of doing the normal click (left click)
using the following function.
------------------------------------------------------------------------------------------------------------------------------------------
function simulateClick() {
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, window,
0, 0, 0, 0, 0, false, false, false, false, 0, null);
var cb = document.getElementById("checkbox");
var canceled = !cb.dispatchEvent(evt);
if(canceled) {
// A handler called preventDefault
alert("canceled");
} else {
// None of the handlers called preventDefault
alert("not canceled");
}
------------------------------------------------------------------------------------------------------------------------------------------

When changing the last but one param of evt.initMouseEvent() from 0 to
2 can i trigger a right click .

Syntax says the last but one is Button 0 - left , 1 - middle , 2 -
right.

Can anybody help me out.

Your response is greatly appriciated.

Thanks
Neps
 
V

VK

I am looking for a way to trigger a Right Click on any HTML element
using javascript.

You can dispatch left and right click events on HTML elements.
You cannot emulate physical user interaction with interface using
artificial events (display right-click context menu, add new options
in multiple select form element etc.) It is a necessary security
measure preventing so called "interface stealing".
 
N

Napoleon

You can dispatch left and right click events on HTML elements.
You cannot emulate physical user interaction with interface using
artificial events (display right-click context menu, add new options
in multiple select form element etc.) It is a necessary security
measure preventing so called "interface stealing".


Thanks for the response. I am more interested in implementation. Is
there a sample implementation for a better understanding.

Thanks again for subsequent response.
Neps
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top