How do I simulate a rightclick on the html element

Discussion in 'Javascript' started by Napoleon, Nov 20, 2007.

  1. Napoleon

    Napoleon Guest

    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
    Napoleon, Nov 20, 2007
    #1
    1. Advertising

  2. Napoleon

    VK Guest

    On Nov 20, 3:43 pm, Napoleon <> wrote:
    > 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".
    VK, Nov 20, 2007
    #2
    1. Advertising

  3. Napoleon

    Napoleon Guest

    On Nov 20, 8:21 pm, VK <> wrote:
    > On Nov 20, 3:43 pm, Napoleon <> wrote:
    >
    > > 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".



    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
    Napoleon, Nov 21, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ken Yu
    Replies:
    8
    Views:
    642
    Justin Beckwith
    Nov 2, 2004
  2. cirfu

    rightclick-copy in IDLE?

    cirfu, Jun 22, 2008, in forum: Python
    Replies:
    1
    Views:
    217
  3. Gelonida
    Replies:
    0
    Views:
    573
    Gelonida
    Feb 19, 2011
  4. Steven Choo
    Replies:
    12
    Views:
    188
    Randy Webb
    Jan 18, 2004
  5. Customize RightClick Menu

    , Sep 5, 2006, in forum: Javascript
    Replies:
    5
    Views:
    75
    Evertjan.
    Sep 6, 2006
Loading...

Share This Page