Detecting which context menu item was selected

B

brisco5

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
 
R

Randy Webb

(e-mail address removed) 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.
 
B

brisco5

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.
 
B

Bart Van der Donck

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 :)
 

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,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top