/    Sign up×
Community /Pin to ProfileBookmark

key to open a link (possible?)

hello,
im making a page with 3 links, and wanted to “associate” keys to those links, so when the site visitor press those keys he can open the respective links..
lets say key “1” (or”a” ) would open link1, key”2″ (or “b”) would open link2, etc
possible?
read something about accesskeys function, but is there any solution where we don´t have to use the “alt” (or other) key with the keys we choose?
thanks.

to post a comment
HTML

3 Comments(s)

Copy linkTweet thisAlerts:
@apeaceMar 10.2008 — There are a couple of ways you could do this:

<a href="linkA.html" accesskey="a" />Press CTRL+A to get this</a>

If you use that, users can press CTRL+A to access the link. However, this doesn't work correctly in many browsers.

Here is another way:

<head>
<script type="text/javascript">
var link1 = "link1.html";//if you press A
var link2 = "link2.html";//if you press B

<i> </i>function goToLink(e){
<i> </i> var keyCode = (window.event) ? event.keyCode : e.keyCode;
<i> </i> switch(keyCode){
<i> </i> case 65:
<i> </i> window.location=link1;
<i> </i> break;
<i> </i> case 66:
<i> </i> window.location=link2;
<i> </i> break;
<i> </i> default:
<i> </i> break;
<i> </i> }
<i> </i>}

<i> </i>document.onkeyup = goToLink;
&lt;/script&gt;
&lt;/head&gt;


Then, all you need to do is create a case for the appropriate ASCII codes, a table of which can be found here:

http://www.comptechdoc.org/os/linux/howlinuxworks/linux_hlkeycodes.html

Does this make sense? Let me know how you fare.
Copy linkTweet thisAlerts:
@data93authorMar 11.2008 — :eek: , thanks a lot , it works perfect and to be honest i wasn´t especting to find a way to this, again thanks a lot !

(by the way , got it working using it other table http://www.petefreitag.com/cheatsheets/ascii-codes/ )
Copy linkTweet thisAlerts:
@apeaceMar 11.2008 — No problem! Keep posting in the community and helping others when you can. Rock on.

Peace!
×

Success!

Help @data93 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...