1

I have a web-application in which I use accesskey attribute to certain buttons. However I can't set alt + F accesskey since it opens the File menu of the firefox. I have tried the following code

onkeydown = function(e){    
    if(e.altKey && e.keyCode == 'F'.charCodeAt(0)) {
    e.stopImmediatePropagation();
    e.stopPropagation();
    return false;
    }
}

It doesn't seems like working in firefox but works fine in chrome. All other alt key combinations can be overridden except alt+F (file menu), alt+E(Edit menu), alt+V(View), alt+S(History), alt+B(Bookmark), alt+T(Tools), alt+H(Help) in firefox.

I am running it in Ubuntu. Is there a way to do it? It should be working in both Windows and Linux.

Sabin Chacko
  • 713
  • 6
  • 17
  • Do you have the option of using a less obtrusive key combination? It might be of value to find a list of key combinations used by major browsers and avoid those. – Aleksandar Misich Mar 24 '17 at 16:16

1 Answers1

0

For alt + f or alt + F following piece of code will work.

onkeydown = function(e){    
   if(event.altKey && event.keyCode == 70) { 
      console.log("alt + f pressed")
      event.preventDefault(); 
   }
}

if by saying alt + F - you mean you want to do alt + shift + f/F - following code will work in that case

onkeydown = function(e){    
   if(event.altKey && event.shiftKey && event.keyCode == 70) { 
      console.log("alt + shift + f/F pressed")
      event.preventDefault(); 
   }
}

Rest of the combinations will work in similar manner Refer to the key code chart here

Misha Akopov
  • 12,241
  • 27
  • 68
  • 82
SBhalla
  • 31
  • 4