"Aaron Fude" <aa*******@yahoo.com> wrote in message news:<cf***********@news.wplus.net>...
Hi,
Can someone give me broad tips on whether it is possible to make a site
keyboard navigatable?
If the html access key solution does not meet your needs, here is a
javascript function that intercepts key presses. The code follows.
Robert
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>shortcut keys</title>
<SCRIPT type="text/javascript">
function processKey(event)
{
if ( typeof event == "object" &&
typeof event.which == "number")
{
// Netscape
alert("event.which = " + typeof event.which + " " + event.which
+
" event.shiftKey = " + event.shiftKey +
" event.ctrlKey = " + event.ctrlKey +
" event.altKey = " + event.altKey +
" event.metaKey = " + event.metaKey);
//control-y goes to yahoo
if (event.which == 121 && event.ctrlKey == true)
{
location.replace("http://www.yahoo.com");
return false;
}
}
else
{
// We assume IE
/*
Big worning: For some reason if you put out an
alert here, the letter will not get get inserted into
a text field.
alert("window.event.keyCode = " + event.keyCode);
*/
// The Netscape & IE keycodes differ.
// It seems easyist just to insert the above alter and see
// what number is shown.
//
//control-y goes to yahoo
if (window.event.keyCode == 25)
{
alert("replacing");
location.replace("http://www.yahoo.com");
return false;
}
}
return true;
}
/* Looks like you can either set the event handler via the
statement below or in the onkeypress event handler of the
html body statement. If you use the statement below, you
will not be passing the event variable to the function
processKey and you will have to preference window to
the event variables for the IE portion of the code.
document.onkeypress = processKey;
*/
</SCRIPT>
</head>
<body onkeypress='return processKey(event);'>
<p>Lets look for a key press.</p>
<form>
<input type=text size=20>
</form>
</body>