Disable Alt functions (shortcuts) in Google Chrome

余生颓废 提交于 2019-12-11 11:37:17

问题


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.


回答1:


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:


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.




回答3:


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.




回答4:


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}


来源:https://stackoverflow.com/questions/14113563/disable-alt-functions-shortcuts-in-google-chrome

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!