Search code examples
angularkeyboard-shortcutsinternet-explorer-11keydown

Disable IE11 browser shortcut keys in Angular application


I am trying to disable shortcuts keys for an Angular application.

I am using the following code in an Angular component:

@HostListener('window:keydown', ['$event'])
 handleHotkey(event: KeyboardEvent){
  ...
  //Do Something 
  ...
  event.preventDefault();
}

This works properly in Google Chrome, but it is not working in Internet Explorer 11.

When I press ctrl+p then in IE11, print window opens along with the functionality which I defined in the function.

What would be the correct way to do this in IE11 ?


Solution

  • Updated:

    It seems like there is no solution for IE. There are 2 (ugly) alternatives: you can disable the Ctrl key entirely, or you can show an alert, and the print window won't show up. :(

    Not working:

    Maybe return false; at the end of your method can solve this, I think.

    But it will cancel every keydown for the browser, so you should write and if statement to check event.keyCode or something like that, to decide if you should return false or true (to let the browser handle the other events).