在我的代码中检测控件 D还触发了Chrome中的书签键盘快捷键,是否有任何方法可以防止这种情况



无论如何是否也有禁用浏览器键盘快捷键的方法吗?Google Chrome键盘快捷键在我的代码之后发生。我只是不想让它走开。

handleKeyDown( e ) {
if ( e.ctrlKey && e.keyCode === 68 ) {  // ctrl + d
    // this works, BUT it also triggers Google Chrome's bookmark shortcut  
}

您应该防止事件的默认操作,例如:

function handleKeyDown( e ) {
  if ( e.ctrlKey && e.keyCode === 68 ) {  // ctrl + d
      // this works, BUT it also triggers Google Chrome's bookmark shortcut
      console.log('Ctrl+D');
  }
  e.preventDefault();
}

https://jsfiddle.net/a5wbd3o9/

最新更新