I'm developing one-page apps. The shortcut should vary from different OSs, especially Mac OS X. Others usually combine keystroke with Ctrl, but Mac combins with Cmd.
Until now, I tried to detect whether the OS is mac or not by this code:
var bMac = navigator.appVersion.indexOf('Mac') > -1;
This code worked well. However, after updating the Chrome to the recent version (37.0.2062.94), it doesn't work anymore.
Is there anyway to detect host OS of browser in JavaScript?
I checked Google Docs in Chrome and it's shortcut worked well with Cmd in Mac and Ctrl in Window. There should be a way to detect OS in JavaScript in Chrome.
EDIT I googled and found some pages about detecting OS in javascript:
It seems that there were some unexpected side effect while upgrading the version. It's still hard to understand.
When I checked the
navigator.appVersion
, it looked strange that there wasLinux; Android...
.I checked the
Emulation
tab in the developer tools, and it looked like this:It was strange that this tab was usually empty. Anyway after I clicked
Reset
button in the tab, it come back.