PDA

View Full Version : Hot Keys



nrsv
03-23-2005, 04:44 PM
Help me! I got a script from the Dynamic Drive that allows me to hot link a key to a web page. How can I do multiple keys?

jscheuer1
03-23-2005, 04:54 PM
whatever
PLEASE: Include a link to your page that you want help with.

nrsv
03-23-2005, 05:07 PM
Sorry, here it is.

http://www.dynamicdrive.com/dynamicindex5/button1.htm

jscheuer1
03-23-2005, 09:33 PM
I'm looking at the script and it appears to have a bug. The demo doesn't work in NS7.2 or FF1.0.1. That being said, the following modified script will work in IE and older versions of NS as does the demo:


<script type="text/javascript">

/*
Hot Key Script- adapted from Home Hot Key Script-
Dynamic Drive (www.dynamicdrive.com)
For full source code, installation instructions,
100's more DHTML scripts, and Terms Of
Use, visit dynamicdrive.com
*/

//configure keys, use as many as you like:
keys="dyg"
//configure destinations, one for each key,
//if you break a line here, do it after a comma:
dest=["http://www.dynamicdrive.com","http://www.yahoo.com",
"http://www.google.com"]
//No need to edit beyond here//
if (document.layers)
document.captureEvents(Event.KEYPRESS)
function go_dest(e){
for (i = 0; i < dest.length; i++){
if (document.layers){
if (e.which==keys.charCodeAt(i))
window.location=dest[i]
}
else if (document.all){
if (event.keyCode==keys.charCodeAt(i))
window.location=dest[i]
}
}
}

document.onkeypress=go_dest

</script>

jscheuer1
03-23-2005, 10:58 PM
Here's one that works in IE6 NS7.2 NN4.79 FF1.0.1, But notice the body 'onkeypress' event handler!


<html>
<head>
<title>Keypress</title>
<script type="text/javascript">

/*
Hot Key Script- adapted from Home Hot Key Script-
Dynamic Drive (www.dynamicdrive.com)
For full source code, installation instructions,
100's more DHTML scripts, and Terms Of
Use, visit dynamicdrive.com
*/

//configure keys, use as many as you like:
keys="dyg"
//configure destinations, one for each key,
//if you break a line here, do it after a comma:
dest=["http://www.dynamicdrive.com","http://www.yahoo.com",
"http://www.google.com"]
//No need to edit beyond here//
if (document.layers)
document.captureEvents(Event.KEYPRESS)
function go_dest(e){
for (i = 0; i < dest.length; i++){
if (document.layers){
if (e.which==keys.charCodeAt(i))
window.location=dest[i]
}
else if (document.all){
if (event.keyCode==keys.charCodeAt(i))
window.location=dest[i]
}
else if ((document.getElementById)&&(!document.all)){
if (e==keys.charCodeAt(i))
window.location=dest[i]
}
}
}

document.onkeypress=go_dest
</script>
</head>
<body onkeypress="if ((document.getElementById)&&(!document.all)){go_dest(event.which)}">
</body>
</html>

mwinter
03-24-2005, 10:22 AM
Here's one that works in IE6 NS7.2 NN4.79 FF1.0.1, But notice the body 'onkeypress' event handler!Be careful when fiddling with keys. You might end up overriding an application key. For example, I might press Ctrl+H in Firefox to bring up my browsing history. If you've bound a URL to H, the History side-bar will open but I'll lose my current page. Also, what if I'm typing in a form control?

Mike

jscheuer1
03-24-2005, 02:56 PM
Be careful when fiddling with keys . . .Good point Mike, I thought this was a somewhat silly script to begin with but, it is what the OP asked for.

nrsv
03-31-2005, 10:05 PM
Thanks for your help