How do you know if the user is using a Mac?

So I found this code online:
window.navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey
window.navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey
The problem is that platform is deprecated, what can I use instead? This is the entire code, basically i'm trying to run a function if the user presses CTRL + S or CMD + S ofc
if (
(window.navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey) &&
e.keyCode == 83
) {
e.preventDefault();
validate();
}
if (
(window.navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey) &&
e.keyCode == 83
) {
e.preventDefault();
validate();
}
5 Replies
ἔρως
ἔρως15mo ago
i wouldn't do any of that, and just check if either control or meta were pressed this way, your code works the same on linux and macos as well
lko
lkoOP15mo ago
right, i'm dumb thank you
ἔρως
ἔρως15mo ago
it's not a matter of you being dumb or smart it's just a matter of simplifying things and this way, you simplify and give the user a choice oh, and it's a lot less work for you too
vince
vince15mo ago
Check the user-agent
ἔρως
ἔρως15mo ago
the user agent can be spoofed, making it effectively useless
Want results from more Discord servers?
Add your server