4 ms·
I actually ran into a case for using UA strings yesterday, if you know of a better solution let me know! I have a canvas element where the user needs to be abl
by MrJohz 4y ago
I actually ran into a case for using UA strings yesterday, if you know of a better solution let me know!
I have a canvas element where the user needs to be able to both scroll and zoom with the mouse wheel. Generally, zooming involves scrolling while also holding the ctrl button down - except on MacOS, where it's cmd. I obviously want to use the operating system conventions that my users will be expecting, but the best way of determining that, that I've found, is searching for the string 'Mac' in the user agent string.
Like I say, if you know of a better way to detect whether I should be binding on ctrl or cmd, let me know! This is the first time I've used the user agent in a long time, and it feels like there should be a better system...
- talkin 4y agoYou mention 2 behaviors: With and without a modifier key. So just accept either key for zooming. :)
- OkayPhysicist 4y agoEspecially considering it is vanishingly unlikely for a Windows user to inadvertently send you a command key down, or the Mac to send you a ctrl down. It's not like you have behaviors to swap.
- MrJohz 4y agoThat's actually a really good idea. I just looked at how a few other sites handle this, and that seems like a common take. I have updated the code!