homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

firefox keypress
how can i adapt this script?

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

I am using a modified version of the script here

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?

<!-- 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) {
// 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 -->



 4:23 am on Jan 25, 2005 (gmt 0)

<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;

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



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

still only works with IE

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved