最近yahoo的邮箱推出了新的测试版,增加了不少很酷的功能,其中的快捷键定义就很方便
用户的使用,俺不知道yahoo究竟是用啥技术实践的,不过俺也知道两种挺简单的方法可以实现网页上的快捷键(如下)
1: 快速定位:可以直接在accesskey属性中设置,设置的快捷键为Alt+设置的key,也可以动态设置,代码如下
[code]<a href="http://toyota2006.iteye.com">toyota's博客</a><br>[/code]
注意:accesskey的优先级是最高点,可以屏蔽掉浏览器的快捷键。但是在没有这种的accesskey的网页上你按下alt+H是什么结果呢?可以看到的是“帮助”啊!自己站上的东西千万不要和IE等的工具冲突。这里列举一下默认&组合:
IE: A(favorites) D(address) E(edit) F(file) H(help) T(tools) V(view)
FireFox:B(bookmark) D(address) E(edit) F(file) G(goto) H(help) T(tools) V(view)
2: 事件处理,
例:按a键时转向到http://toyota2006.iteye.com
[code]<html>
<head>
<title> </title>
<SCRIPT language="javascript">
var hotkey=97 //设置快捷键为a
var destination="http://toyota2006.iteye.com"
if (document.layers)
document.captureEvents(Event.KEYPRESS)
function backhome(e){
if (document.layers){
if (e.which==hotkey)
window.location=destination
}
else if (document.all){
if (event.keyCode==hotkey)
window.location=destination
}}
document.οnkeypress=backhome
</SCRIPT>
</head>
<body οnlοad="backhome()">
</body>
</html>[/code]
用户的使用,俺不知道yahoo究竟是用啥技术实践的,不过俺也知道两种挺简单的方法可以实现网页上的快捷键(如下)
1: 快速定位:可以直接在accesskey属性中设置,设置的快捷键为Alt+设置的key,也可以动态设置,代码如下
[code]<a href="http://toyota2006.iteye.com">toyota's博客</a><br>[/code]
注意:accesskey的优先级是最高点,可以屏蔽掉浏览器的快捷键。但是在没有这种的accesskey的网页上你按下alt+H是什么结果呢?可以看到的是“帮助”啊!自己站上的东西千万不要和IE等的工具冲突。这里列举一下默认&组合:
IE: A(favorites) D(address) E(edit) F(file) H(help) T(tools) V(view)
FireFox:B(bookmark) D(address) E(edit) F(file) G(goto) H(help) T(tools) V(view)
2: 事件处理,
例:按a键时转向到http://toyota2006.iteye.com
[code]<html>
<head>
<title> </title>
<SCRIPT language="javascript">
var hotkey=97 //设置快捷键为a
var destination="http://toyota2006.iteye.com"
if (document.layers)
document.captureEvents(Event.KEYPRESS)
function backhome(e){
if (document.layers){
if (e.which==hotkey)
window.location=destination
}
else if (document.all){
if (event.keyCode==hotkey)
window.location=destination
}}
document.οnkeypress=backhome
</SCRIPT>
</head>
<body οnlοad="backhome()">
</body>
</html>[/code]