在浏览器中获取快捷键的关键组合 [英] Getting the key combination of accesskeys in a browser

查看:103
本文介绍了在浏览器中获取快捷键的关键组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个页面,其中某些输入和链接具有附加的访问密钥,我想告诉用户他们需要按什么组合键来激活输入或链接。有没有办法通过JavaScript自动获取浏览器的accesskey组合键,还是需要检测它是哪个浏览器,然后使用一个表来存储浏览器使用的组合键?

我还没有发现任何脚本可以自动检测到这一点(我已经看过维基百科的源代码,并且他们也通过浏览器名称),我觉得它很好奇,因为大多数网站似乎推荐功能检测,而不是浏览器检测。如果访问键会成为例外情况,我会觉得很奇怪。



另外,根据维基百科,有很多不同的快捷键组合,所以我不认为制作一系列组合和挑选浏览器的组合是最好的解决方案。 / p>

解决方案

根据HTML5,有一个 JS属性,称为 accessKeyLabel ,它应该返回一个适合浏览器的字符串,基于 accesskey 属性



可能无法在所有浏览器/版本中工作,但是,在其中如果您需要手动浏览器嗅探和分支回退功能。 10-20个这样的组合不是一个巨大的数量的恕我直言,也是唯一合理的追索权。

I want to make a page where certain inputs and links have accesskeys attached to them, and I want to inform the user of what key combination they need to press to activate the input or link. Is there a way to automatically get the accesskey key combination of a browser via JavaScript, or do I need to detect which browser it is and then just use a table where I store the key combination that browser uses?

I haven't found any scripts that could automatically detect this (I've looked at the source code for Wikipedia, and they also go by browser name), which I find curious, since most sites seem to recommend feature detection as opposed to browser detection. I would find it weird if accesskeys would be the exception to that.

Also, according to Wikipedia, there's a huge load of different key combinations for accesskeys, so I don't think making an array of combinations and picking the browser's combination would be the best solution for that.

解决方案

Per HTML5, there is a JS attribute called accessKeyLabel that should return a string appropriate to the browser, based on the value of the accesskey attribute.

This may not work across all browsers/versions that you care about, however, in which case you will need a manual browser-sniffing-and-branching fallback. 10–20 such combinations are not a "huge" amount IMHO, and the only reasonable recourse.

这篇关于在浏览器中获取快捷键的关键组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆