Detecting which context menu item was selected

Discussion in 'Javascript' started by brisco5@gmail.com, Jun 29, 2006.

  1. Guest

    I have a TEXTAREA element. A user right clicks within in to get the
    context menu and they select "paste". I want my javascript code to
    know that they selected "paste".
    I know you can capture the mouse click, but can we capture exactly what
    event that attempted?

    Thanks,
    Mike
    , Jun 29, 2006
    #1
    1. Advertising

  2. Randy Webb Guest

    said the following on 6/29/2006 4:54 PM:
    > I have a TEXTAREA element. A user right clicks within in to get the
    > context menu and they select "paste".


    OK, but that is not the only way to "paste". There are at least 3 other
    ways.

    > I want my javascript code to know that they selected "paste".


    Do you want to know they selected "paste" from that menu or that they
    pasted text into your textarea? The difference in the two is astronomical.

    > I know you can capture the mouse click, but can we capture exactly what
    > event that attempted?


    Doubtful, depending on what you are really trying to do.

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Temporarily at: http://members.aol.com/_ht_a/hikksnotathome/cljfaq/
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
    Randy Webb, Jun 29, 2006
    #2
    1. Advertising

  3. Guest

    Ultimately, I'm trying to keep a running total of how many characters
    are in the TEXTAREA. So really, however text can be entered, whether
    it's keyed or pasted (context menu, control+v), I want to be able to
    get the total.
    Randy Webb wrote:
    > said the following on 6/29/2006 4:54 PM:
    > > I have a TEXTAREA element. A user right clicks within in to get the
    > > context menu and they select "paste".

    >
    > OK, but that is not the only way to "paste". There are at least 3 other
    > ways.
    >
    > > I want my javascript code to know that they selected "paste".

    >
    > Do you want to know they selected "paste" from that menu or that they
    > pasted text into your textarea? The difference in the two is astronomical.
    >
    > > I know you can capture the mouse click, but can we capture exactly what
    > > event that attempted?

    >
    > Doubtful, depending on what you are really trying to do.
    >
    > --
    > Randy
    > comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    > Temporarily at: http://members.aol.com/_ht_a/hikksnotathome/cljfaq/
    > Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
    , Jun 29, 2006
    #3
  4. wrote:

    > I have a TEXTAREA element. A user right clicks within in to get the
    > context menu and they select "paste". I want my javascript code to
    > know that they selected "paste".
    > I know you can capture the mouse click, but can we capture exactly what
    > event that attempted?


    I 'ld say you should use as much event handlers as possible then. The
    following could be a start (but not complete!):

    <script type="text/javascript">
    function updateBox(nr) {
    document.forms[0].howmany.value = nr
    }
    </script>
    <form method="get">
    <textarea name="txt" cols="30" rows="5"
    onclick="updateBox(this.value.length)"
    ondblclick="updateBox(this.value.length)"
    onmousedown="updateBox(this.value.length)"
    onmouseup="updateBox(this.value.length)"
    onmouseover="updateBox(this.value.length)"
    onmousemove="updateBox(this.value.length)"
    onmouseout="updateBox(this.value.length)"
    onkeypress="updateBox(this.value.length)"
    onkeydown="updateBox(this.value.length)"
    onkeyup="updateBox(this.value.length)"
    onfocus="updateBox(this.value.length)"
    onblur="updateBox(this.value.length)"
    onselect="updateBox(this.value.length)"
    onchange="updateBox(this.value.length)"
    >

    </textarea><br>
    Length:
    <input type="text" size="4" name="howmany" value="0">
    </form>

    Further handlers:

    http://www.w3.org/TR/DOM-Level-2-Events/events.html
    http://msdn.microsoft.com/workshop/author/dhtml/reference/events.asp
    http://developer.mozilla.org/en/docs/DOM:element#Event_Handlers

    I would just put them all in the code. Brute force, you know :)

    --
    Bart
    Bart Van der Donck, Jun 30, 2006
    #4
    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. Iain
    Replies:
    3
    Views:
    919
  2. Replies:
    0
    Views:
    1,418
  3. mldardy
    Replies:
    0
    Views:
    954
    mldardy
    Sep 28, 2010
  4. Andy Fish
    Replies:
    1
    Views:
    96
    Csaba Gabor
    Jun 15, 2005
  5. lcplben
    Replies:
    3
    Views:
    481
    Garrett Smith
    Oct 30, 2009
Loading...

Share This Page