admin管理员组文章数量:1357583
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.
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.
Share Improve this question edited Jan 1, 2013 at 19:43 Idrizi.A asked Jan 1, 2013 at 19:37 Idrizi.AIdrizi.A 12.1k15 gold badges51 silver badges90 bronze badges5 Answers
Reset to default 2Browsers 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.
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
.
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/' accesskey='f'>
Link to www.example (accesskey: f)
</a>
<p/>
<a href='http://apache/' accesskey='a'>
Link to apache (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.
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).
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}
本文标签: javascriptDisable Alt functions (shortcuts) in Google ChromeStack Overflow
版权声明:本文标题:javascript - Disable Alt functions (shortcuts) in Google Chrome - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743980864a2571075.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论