0 points

Test if Mac or PC with JavaScript


dashboard

Tue Jun 23 2020 09:04:03 GMT+0000 (UTC)

Posted by @Amna #javascript

if (navigator.userAgent.indexOf('Mac OS X') != -1) {
  $("body").addClass("mac");
} else {
  $("body").addClass("pc");
}
content_copy Copy

User Agent testing sucks, but sometimes you need it for subtle things. In my case I was using it to adjust what I was showing for keyboard shortcut keys (Command or Control). Nothing super major.

https://css-tricks.com/snippets/javascript/test-mac-pc-javascript/