Short cut key to open pages
i have 5 links in my home page ,
linkabc linkdef linkghi linkjkl linkmno
when i click the CTRL+b to open the linkabc page ,
When i click the C开发者_运维知识库TRL+e to open the linkdef page like wise,
How to do this functionality with few snnipet ,
The vanilla javascript way:
You'll need to bind to the onkeydown event, then retrieve the keycode. Get keycodes here: http://www.cambiaresearch.com/c4/702b8cd1-e5b0-42e6-83ac-25f0306e3e25/Javascript-Char-Codes-Key-Codes.aspx
For modifier keys, you'll need to maintain variables to check if they are depressed. For instance, if the keycode for control is detected onkeydown, toggle the var control = true
. Onkeyup, you'll toggle back: var control = false
. To trigger the action, you'll do:
if (control && e.keycode == 66) { // 66 happens to be "b"
performAction();
}
This is much easier if you're using a library, though, as there are plugins for all major javascript libraries for keybindings, such as this one for jQuery: http://plugins.jquery.com/project/hotkeys
No Javascript needed.
<a accesskey="b" href="#">linka<u>b</u>c</a>
<a accesskey="e" href="#">linkd<u>e</u>f</a>
You can access the first link by pressing Alt-b
, the second by Alt-e
.
This post has a little Javascript library that lets you bind keyboard shortcuts. Might try looking into that. He has a little demo on that page and it seems to work pretty well.
You can do it using the accesskey attribute of the Html Anchor tag as follows but you will press ALT instead of CTRL:-
<a accesskey="b" href="linkabc.html">linka<u>b</u>c</a>
<a accesskey="e" href="linkdef.html">linkd<u>e</u>f</a>
I hope this helps you and you can check this url for more information:-
http://en.wikipedia.org/wiki/Access_key
精彩评论