WebDialogs and JavaScript events
-
Developers:
While developing my CameraControls plugin, I discovered some irritating differences between browsers and JavaScript reporting of events (such as onmousemove, onmousedown, etc). That shouldn't be surprising, but it was unexpected.
In my particular case, the issue was with collecting a left mouse button event. The real issue (IMHO) is that the W3C spec is to blame. Here's why:
Per W3C specs, event.button returns a value of 0-2 based on the button pushed.
LMB returns 0
MMB returns 1
RMB returns 2
These are not bit-coded, so there's no way to handle concurrent clicks (if you wanted to do that for some reason).In IE, event.button returns a value of 0,1,2, or 4, or combination thereof:
No mouse button returns 0
LMB returns 1
RMB returns 2
MMB returns 4
These ARE bit-coded, so a concurrent LMB+RMB (for example) would return 3.The W3C spec is crazy (to me), because the default value is the same as the LMB value, making it impossible with event.button to determine a left click. However, most non-IE browsers also return event.which:
LMB returns 1
MMB returns 2
RMB returns 3That's fine, except I ran into problems trying to call document.onmousedown=function in Safari(!). The defined method would fire once at load, and would refuse to fire subsequently no matter how many times I pressed my mouse button. Irritating.
The workaround for that issue was to add onmousedown events to specific objects in the document (in my case, the slider buttons). That required additional code to handle other issues that in the PC version were handled more simply with event.button.
Anyway, just some things to be aware of when trying to use DHTML+JS in WebDialogs...
-
I'm using jQuery to take care of such things.
Advertisement