click event - mouse or keypress

A

andy.hume

Hello,

Is there any cross-browser method of determining whether a click event
was triggered by a mouse left click or the keyboard's 'enter' key? I
was expecting event.button, or event.which to be able to do this, but
this doesn't seem to be the case. Checking event.clientX == 0 &&
event.clientY == 0 works in FF, but not in IE.

Anything else I can try?

Cheers,
Andy.
 
T

Thomas 'PointedEars' Lahn

Is there any cross-browser method of determining whether a click event
was triggered by a mouse left click or the keyboard's 'enter' key?

I don't think so.
I was expecting event.button,
http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-MouseEvent-button

or event.which to be able to do this, but this doesn't seem to be the case.

You will observe that `click' is a mouse event type:
Checking event.clientX == 0 && event.clientY == 0 works in FF, but not in IE.

http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-MouseEvent-clientX

MSHTML appears to implement the button property in a non-standard way for
onmouse* events, so you could check for the value 0 there:

http://msdn2.microsoft.com/en-us/library/ms533544.aspx

MSHTML also implements a keyCode property:

http://msdn2.microsoft.com/en-us/library/ms533927.aspx
Anything else I can try?

Use the key* events to determine whether or not a key was used.


PointedEars
 

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,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top