1
votes

I use the following code (as shortcut) to redirect users on my feedback page.

<a href='/feedback/' accesskey='f'>feedback</a>

But this code does not work in Google Chrome because when user presses Alt + F it will open the Google Chrome menu bar.

How do I disable those 'shortcuts'?

It can be jQuery, javascript...

Note: I have written a javascript code that redirects, but it firstly opens the Chrome menu bar then does its job.

5

5 Answers

2
votes

There are certain special keys that are reserved and Alt+F is one of them but it will really vary between browsers and operating systems. Here's a good article.

2
votes

Browsers that allow this theoretically expose a security vulnerability. If it's possible to override "system" behaviors, you could hijack the users browser. It would be able to pop up a fake "File" menu that simulates the real one and makes the user think they are interacting with their own local machine instead of a web site.

Because of this it's impossible in most modern browsers.

2
votes

In Google Chrome (tested in V44), the modifier key to access accesskey keyboard shortcuts is Alt.

However, if the key conflicts with a browser shortcut, it is accessed with AltShift. So the solution you posted works, but only using AltShift.

Example:

  • the first link is accessed with AltShift+f (conflict with menu shortcut)
  • the second link is accessed with Alt+a (no conflict)

<h1>Links with accesskey attribute</h1>

<a href='http://www.example.org/' accesskey='f'>
Link to www.example.org (accesskey: f)
</a>
<p/>
<a href='http://apache.org/' accesskey='a'>
Link to apache.org (accesskey: a)
</a>

Incidentally, I prefer the solution Firefox uses, which is to always use AltShift for these shortcuts. This is more consistent for users than Chrome's behavior (though the Chome devs may have had their reasons).


Note: The above is valid on Windows and Linux. AFAIK, Chrome on Mac OS X uses different shortcuts.

1
votes

I just found a way how to disable browser functions when user presses Alt + other button. Javascript can disable this shortcuts by writing at the end of the function return false

Example

function function1(){/* code goes here */; return false}
0
votes

As others have stated, it's probably not a good idea.

But if you're a madlad and you like doing what you want, this will actually work:

document.addEventListener('keydown', (e) => {
  e.preventDefault();
  if (e.altKey) {
    console.log('yay');
  }
})

e.preventDefault() needs to be placed at the top of the event handler. This prevents the browser's default behavior (ie., opening menus).