homepage Welcome to WebmasterWorld Guest from 54.204.67.26
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor
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?
WhosAWhata




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

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>

 

MikeFoster




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

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

WhosAWhata




msg:1487290
 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.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved