Search code examples
javascriptpreventdefault

Javascript to prevent Alt+Shift default action or to detect multiple OS languages


I was intending to prompt my users to hold Alt+Shift for a particular aspect of my website. Having written the script, I discovered that in Windows where multiple languages are enabled, this toggles between them, which would not be desirable for the user.

Ideally, I would like to prevent this default toggle whilst on this particular web page or perhaps alternatively check first to see if multiple languages are enabled on windows. As far as I can tell it’s not possible to do either?

The following does not prevent the toggle:

e.preventDefault ? e.preventDefault() : event.returnValue = false;

This only detects the languages in the browser, not the OS:

navigator.languages ? navigator.languages[0] : (navigator.language || navigator.userLanguage)

Solution

  • The key combination is intercepted by Windows, it never reaches the browser, so there's nothing you can do from within a website. The browser doesn't even know about this functionality, so you cannot check for it, either. Choose a different key combination.