Reputation: 25733
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 CTRL+e to open the linkdef page like wise,
How to do this functionality with few snnipet ,
Upvotes: 1
Views: 315
Reputation: 542
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
Upvotes: 0
Reputation: 43
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
.
Upvotes: 1
Reputation: 16655
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.
Upvotes: 0
Reputation: 3633
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
Upvotes: 1