Welcome to WebmasterWorld Guest from 54.205.20.160

Forum Moderators: open

Message Too Old, No Replies

firefox keypress

how can i adapt this script?

   
3:39 am on Jan 25, 2005 (gmt 0)

10+ Year Member



I am using a modified version of the script here
[javascript.internet.com...]

it basically just changes the page when you hit certain keys
it works in IE (and supposedly in Netscape but i haven't tried) but not with firefox

how can i modify it?


<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var key = new Array(); // Define key launcher pages here
key['n'] = "URL1";
key['l'] = "Url2";
key['s'] = "url3";
key['r'] = "url4";
function getKey(keyStroke) {
isNetscape=(document.layers);
// Cross-browser key capture routine couresty
// of Randy Bennett (rbennett@thezone.net)
eventChooser = (isNetscape)? keyStroke.which : event.keyCode;
which = String.fromCharCode(eventChooser).toLowerCase();
for (var i in key) if (which == i) window.location= key[i];
}
document.onkeypress = getKey;
// End -->
</script>
4:23 am on Jan 25, 2005 (gmt 0)

10+ Year Member



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<script type='text/javascript'>
var keys = new Array(); // Define key launcher pages here
keys['n'] = "URL1";
keys['l'] = "Url2";
keys['s'] = "url3";
keys['r'] = "url4";
window.onload = function()
{
document.onkeypress = docOnKeypress;
}
function docOnKeypress(evt)
{
var e = evt? evt : window.event;
if(!e) return;
var key = 0;
if (e.keyCode) { key = e.keyCode; } // for moz/fb, if keyCode==0 use 'which'
else if (typeof(e.which)!= 'undefined') { key = e.which; }
//
var url = keys[String.fromCharCode(key)];
if (url) {
window.location.href = url;
}
}
</script>
</head>
<body>

For reference: key events demo [cross-browser.com]

</body>
</html>

4:27 am on Jan 26, 2005 (gmt 0)

10+ Year Member



still only works with IE