2

The use of navigator.userAgent is not advised as per MDN. In my application I want to have a shortcut for del key.

In mac del key (is backspace) with charCode = 8. In windows del key charCode = 46.

I want to treat both keyEvents same. I am currently using userAgent but it is unreliable as that property can be spoofed. I am wondering what is the best way to know the client OS otherwise.

More deprecated navigator properties navigator.appVersion navigator.platform

/* code objective */
if ((keycode == 8 && os == 'macintosh') || keycode == 46) {
    //This is keyboard shortcut to perform delete
}
11

1 Answer 1

1

Relying on KeyboardEvent.metaKey and KeyboardEvent.Backspace solved my problem

Full Key Values - https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values

For more details refer: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key#Key_values

Thanks to @Teoli2003 for twitter reply - https://twitter.com/Teoli2003/status/663995373766221824

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.